如何使用JavaScript禁用滚动条? [英] How to disable scrollbars with JavaScript?

查看:109
本文介绍了如何使用JavaScript禁用滚动条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to lock the browser scrollbars when I show a div that represent a modal window in Internet Explorer 7 only. Googling I found that I can use document.body.style.overflow='hidden' but this doesn't work for IE7. I also tried with document.body.scroll="no" which works but only after I mouse over the scrollbar :-S

有人知道更好的方法吗?

Does anybody knows a better aproach?

Thansks

推荐答案

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

To answer your various questions (including that in your other comment), I think you're using the wrong positioning method.

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

Try position:fixed. It's basically the same as position:absolute apart from it's relative to the absolute viewport. Ie: if the user scrolls, the item stays in the same place on the screen.

因此,考虑到这一点,您可以布置位置:固定叠加。在其中你可以拥有你的位置:绝对(或修复再次,如果你愿意 - 它应该没有't 有所作为)模态框。

So with this in mind, you can lay out a position:fixed overlay. Within that you can have your position:absolute (or fixed again, if you prefer -- it shouldn't make a difference) modal box.

这篇关于如何使用JavaScript禁用滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆