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

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

问题描述

可能重复:
如何禁用浏览器或元素滚动条,但允许使用滚轮或方向键滚动?

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.

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

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