当我在Internet Explorer 7中显示代表模式窗口的div时,我需要锁定浏览器滚动条。 谷歌搜索我发现我可以使用 document.body.style.overflow ='hidden'但这对IE7不起作用。我也尝试使用 document.body.scroll =" no" ,只有在我将鼠标悬停在滚动条上后才能工作:-S

有人知道更好的方法吗?

Thansks

有帮助吗?

解决方案

要回答您的各种问题(包括您在其他评论中的问题),我认为您使用的是错误的定位方法。

尝试 position:fixed 。它与 position:absolute 基本相同,除了它相对于绝对视口。即:如果用户滚动,则该项目停留在屏幕上的相同位置。

因此,考虑到这一点,您可以布置位置:fixed overlay。在其中,您可以拥有位置:绝对(或 fixed ,如果您愿意 - 它不应该有所作为)模式框

其他提示

设置你的模态叠加div来填充身体,所以即使他们滚动,他们也无能为力,因为一切都隐藏在它下面。

你也可以使用 overflow:hidden 隐藏滚动条,这样用户就不会看到scollbars所以它不会受到诱惑:)

这可以帮到你:

documentOBJ = {
    /*Width and Height of the avaible viewport, what you'r seeing*/
    window : {
        x : function(){return (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth; },
        y : function(){return (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight;}
    },

    /*Scroll offset*/ 
    scroll : {
        x : function(){return ( document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft; },
        y : function(){return ( document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop; }
    },

    /*Height and width of the total of the xhtml in a page*/
    page : {
        x : function(){return (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth; },
        y : function(){return (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight; }
    },
    pointer : {}
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top