當我在Internet Explorer 7中顯示代表模式窗口的div時,需要鎖定瀏覽器滾動條。 使用谷歌搜索,我發現我可以使用document.body.style.overflow='hidden'
但這不適用於IE7。我也嘗試過document.body.scroll="no"
這是可行的,但只有當我將鼠標移過滾動條後:-S如何禁用JavaScript的滾動條?
有沒有人知道更好的方法?
Thansks
當我在Internet Explorer 7中顯示代表模式窗口的div時,需要鎖定瀏覽器滾動條。 使用谷歌搜索,我發現我可以使用document.body.style.overflow='hidden'
但這不適用於IE7。我也嘗試過document.body.scroll="no"
這是可行的,但只有當我將鼠標移過滾動條後:-S如何禁用JavaScript的滾動條?
有沒有人知道更好的方法?
Thansks
要回答您的各種問題(包括您在其他評論中的問題),我認爲您使用了錯誤的定位方法。
嘗試position:fixed
。它基本上與position:absolute
相同,只是它與絕對視口相關。即:如果用戶滾動,該項目停留在屏幕上的相同位置。
因此,考慮到這一點,你可以佈置一個position:fixed
覆蓋。在那裏,你可以有你的position:absolute
(或fixed
再次,如果你願意 - 不應該有所作爲)模態框。
設置你的模式疊加div來補身體,所以即使他們滾動沒有什麼可以做,因爲一切都隱藏在它下面。
,你也可以隱藏通過overflow:hidden
滾動條,使用戶不會看到scollbars所以它不會受到誘惑,以scoll各地:)
這可以幫助你:
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 : {}
}
你怎麼大小在IE7中的視口?我無法使用以下任何一種方法獲取身體的實際尺寸: window.innerHeight,document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.body.clientHeight 頁面有一個大小約2000像素 – Flupkear 2009-01-07 20:59:11
你不能只使用100% – 2009-01-07 21:08:02