简体   繁体   English

IE6中的模态居中问题

[英]Modal centering problem in IE6

I'm using a popup modal on my site but have an issue with the dreaded IE6. 我在网站上使用了弹出模式,但可怕的IE6出现了问题。
The modal pops up smack bang in the middle of the page until the page is a long scroll, then IE6 opens the modal but you need to scroll up to find it. 模式会在页面中间弹出提示音,直到页面滚动很长为止,然后IE6打开模式,但是您需要向上滚动才能找到它。

The code I'm using is as follows. 我正在使用的代码如下。

$(id).css('top',  winH/2-$(id).height()/2);  
$(id).css('left', winW/2-$(id).width()/2);  

Can anyone suggest a hack for IE6. 谁能建议IE6遭到入侵。
Thanks. 谢谢。

This shouldn't work on other browsers either, as you didn't supply the page scroll offset. 这也不适用于其他浏览器,因为您没有提供页面滚动偏移量。 You should also save the element to a variable to save jQuery from traversing the DOM four times and you can also combine the css declarations into one. 您还应该将元素保存到变量中,以防止jQuery遍历DOM四次,还可以将css声明合并为一个。 Try this: 尝试这个:

var el = $(id);
el.css({
    top:  $(window).scrollTop() + winH / 2 - el.height() / 2,
    left: winW / 2 - el.width() / 2
});  

Other method is to use the document height instead of window height. 另一种方法是使用文档高度而不是窗口高度。 Window height is the height of the page currently visible on the screen, and document height is the height of the whole page. 窗口高度是屏幕上当前可见页面的高度,文档高度是整个页面的高度。 Using document height: 使用文件高度:

var el = $(id);
el.css({
    top:  $(document).height() / 2 - el.height() / 2,
    left: winW / 2 - el.width() / 2
});  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM