I am using this following code to position the dialog to the center of the window.
var dialog = $('#dialogBox');
var windowHeight = $(window).height();
var windowWidth = $(window).width();
var dHeight = $('#dialogBox').height();
var dWidth = $('#dialogBox').width();
$('#dialogBox').css({top:windowHeight/2 - dHeight/2, left:windowWidth/2 - dWidth/2}).show();
It positions the div to the center of the window. But i wants to position the dialog to the center of current visible area. So the dialog will be positioned center of the window even if i scroll down or scroll up. How to do it with jquery?
Any suggestions would be appreciative!!!
Thanks.
You can make it dead-centered like this:
Note that element will appear at the center but with scrolling it won’t move. If you want to make it appear at center, you need to set
positiontofixedinstead. However, this won’t work in IE6. So decision is yours 🙂You can also create quick simple jQuery plugin:
And later use it like: