删除HTML滚动条,但允许鼠标滚轮滚动 [英] Remove HTML scrollbars but allow mousewheel scrolling
问题描述
我可以通过设置CSS属性 overflow-y来禁用网格中的垂直滚动条:隐藏
。但是,这消除了用鼠标滚轮滚动内容的能力。
有没有办法显示滚动条,但仍然允许滚动内容鼠标滚轮或箭头键?
有Javascript方法,请参阅您重复的线程。
更好的解决方案是将target div设置为overflow:scroll,并将其包装在第二个元素中,该元素的宽度为8px,溢出:hidden。
目标元素将有一个隐藏的滚动条。
< div style ='overflow:hidden;这个鼠标滚轮可以工作,但滚动条不会显示。宽度:200像素;>
< div style ='overflow:scroll;宽度:208px>
我的滚轮滚动内容在这里....
< / div>
< / div>
请注意,8px作为滚动条的宽度是一个随机数 - 它可能更多,并且它可能需要每个浏览器CSS。
在我的书中比JS还要好。
Possible Duplicate:
How to disable browser or element scrollbar, but allow scrolling with wheel or arrow keys?
I was able to disable vertical scrollbars in a grid by setting the CSS property overflow-y: hidden
. However, this removed the ability to scroll the contents with the mouse wheel as well.
Is there a way to not show the scrollbars but still allow the contents to be scrolled through mouse wheel or arrow keys?
There are Javascript methods, see the thread you duplicated.
A better solution is to set the target div to overflow:scroll, and wrap it inside a second element that is 8px narrower, who's overflow:hidden.
The target element will have a hidden scrollbar. The mousewheel will work, but the scroll bar will not show.
<div style='overflow:hidden; width:200px;'>
<div style='overflow:scroll; width:208px'>
My mousewheel scrollable content here....
</div>
</div>
Note that 8px as the width of the scrollbar is a random number - it's probably a lot more, and it could require per browser CSS.
Still better than JS in my book.
这篇关于删除HTML滚动条,但允许鼠标滚轮滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!