I have made script that center div on center of browser window, and my problem is here:
The script takes a width and height of overlay_window before it loads content, so it centres div like for 1px x 1px element, right after this it loads contents and I don`t know how to prevent this.
Can someone help me?
Here the code:
$(document).ready( function(){
$('.cod').click(function() {
var div_name = $(this).attr('id');
$('.overlay_window').load('/templates/' + div_name + '_template.php');
var div_width = $('#'+div_name+'-overlay').width();
var div_height = $('#'+div_name+'-overlay').height();
$('.overlay_window').css("width", ""+div_width+"px")
$('.overlay_window').css("height", ""+div_height+"px")
var div2_width = $('.overlay_window').width();
var div2_height = $('.overlay_window').height();
var window_width = $(window).width();
var window_height = $(window).height();
var widthoffset = (window_width - div2_width) / 2;
var heightoffset = (window_height - div2_height) / 2;
$('.overlay_window').css("left", "" + (widthoffset-div_width) + "px");
$('.overlay_window').css("top", "" + (heightoffset-div_height) + "px");
$('.overlay_background').fadeIn();
$('.overlay_window').fadeIn();
});
});
and CSS:
div.overlay_window{
background:#ffffff;
width:auto;
height:auto;
position:absolute;
z-index:200;
top:0;
left:0;
}
Make your style changes when data is loaded from .load(url, completed) function. You simple asked to load page and while it loadings, you make your style changes.