2009-01-07 65 views
4

当我在Internet Explorer 7中显示代表模式窗口的div时,需要锁定浏览器滚动条。 使用谷歌搜索,我发现我可以使用document.body.style.overflow='hidden'但这不适用于IE7。我也尝试过document.body.scroll="no"这是可行的,但只有当我将鼠标移过滚动条后:-S如何禁用JavaScript的滚动条?

有没有人知道更好的方法?

Thansks

回答

13

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

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

因此,考虑到这一点,你可以布置一个position:fixed覆盖。在那里,你可以有你的position:absolute(或fixed再次,如果你愿意 - 不应该有所作为)模态框。

2

设置你的模式叠加div来补身体,所以即使他们滚动没有什么可以做,因为一切都隐藏在它下面。

+0

你怎么大小在IE7中的视口?我无法使用以下任何一种方法获取身体的实际尺寸: window.innerHeight,document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.body.clientHeight 页面有一个大小约2000像素 – Flupkear 2009-01-07 20:59:11

+0

你不能只使用100% – 2009-01-07 21:08:02

0

,你也可以隐藏通过overflow:hidden滚动条,使用户不会看到scollbars所以它不会受到诱惑,以scoll各地:)

0

这可以帮助你:

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 : {} 
}