隐藏滚动条,同时仍然能够使用鼠标/键盘滚动 [英] hide scrollbar while still able to scroll with mouse/keyboard

查看:137
本文介绍了隐藏滚动条,同时仍然能够使用鼠标/键盘滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

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

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.

这篇关于隐藏滚动条,同时仍然能够使用鼠标/键盘滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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