隐藏滚动条,同时仍然可以使用鼠标/键盘滚动
Possible Duplicate:
How to disable browser or element scrollbar, but allow scrolling with wheel or arrow keys?
我想知道是否可以隐藏滚动条,而仍然可以使用鼠标/键盘启用滚动.
I want to know if it is possible to hide the scrollbar, while scrolling is still enabled with mouse/keyboard.
我尝试使用CSS:overflow: hidden;
.效果是禁用滚动条和禁用滚动.
I tried to use CSS: overflow: hidden;
. The effect is scrollbar disabled and scrolling disabled.
对于将来的参考,还有一种不使用jQuery的解决方案-仅使包装div样式包含overflow:hidden
并使用此JavaScript两层式:
For future reference there is also a solution without jQuery - just have the wrapper div style contain overflow:hidden
and use this JavaScript two-liner:
// get the width of the textarea minus scrollbar
var textareaWidth = document.getElementById("textarea").scrollWidth;
// width of our wrapper equals width of the inner part of the textarea
document.getElementById("wrapper").style.width = textareaWidth + "px";
请参见演示或完整填写 更新:您可以使用相同的原理创建不带滚动条的可滚动div:
Update: you can use the same principle to create scrollable div without scrollbar: demo.