隐藏滚动条,同时仍然能够使用鼠标/键盘滚动

问题描述:


可能重复:

我想知道是否可以隐藏滚动条,而滚动仍然可以使用鼠标/键盘。

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";

请参阅演示或完成 HOWTO

更新:您可以使用相同的原理来创建不含滚动条的可滚动div:演示

Update: you can use the same principle to create scrollable div without scrollbar: demo.