I’m having problems with my modal window positioning. I’ve been trying to use $(document).height() and $(window).height() and its not giving me what I wanted. This will give me the right positioning if I’m on the top page, but if I scroll down somewhere on my page. The modal will position itself on the top page, and not where I’m viewing in the browser.
Someone please help me 🙂 Been working on this for a long time
Thank you
jquery :
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeIn(1);
$('#mask').fadeTo("fast",0.8);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
id.css('top', (winH - id.outerHeight()) / 2);
id.css('left', ' (winW- id.outerWidth()) / 2);
//transition effect
id.show();
CSS
.imageBox .window {
left:0;
top:0;
text-align:center;
position:absolute;
display:none;
z-index:9999;
padding:20px;
}
I don’t want to use position:fixed; because if the modal window gets too large in height, I won’t be able to scroll to the content that’s outside of the window view
You should check how much you have scrolled to include it in your calculus, with:
Hope this helps. Cheers