Jquery 模态窗口定位帮助!
我的模态窗口定位有问题。我一直在尝试使用$(document.height()和$(window.height()),但它并没有给我想要的东西。这将给我正确的定位,如果我在顶部页面,但如果我向下滚动我的页面上的某个地方。模态将自身定位在首页,而不是我在浏览器中查看的位置 有人请帮帮我:)这件事已经做了很长时间了 多谢各位 jquery:Jquery 模态窗口定位帮助!,jquery,position,positioning,modal-dialog,Jquery,Position,Positioning,Modal Dialog,我的模态窗口定位有问题。我一直在尝试使用$(document.height()和$(window.height()),但它并没有给我想要的东西。这将给我正确的定位,如果我在顶部页面,但如果我向下滚动我的页面上的某个地方。模态将自身定位在首页,而不是我在浏览器中查看的位置 有人请帮帮我:)这件事已经做了很长时间了 多谢各位 jquery: //Get the screen height and width var maskHeight = $(document).height();
//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
我不想使用位置:固定;因为如果模式窗口的高度太大,我将无法滚动到窗口视图之外的内容您应该检查滚动了多少以将其包含在演算中,方法是:
var pixelsScrolled = $(document).scrollTop();
希望这有帮助。干杯
var pixelsScrolled = $(document).scrollTop();