删除 HTML 滚动条但允许鼠标滚轮滚动 [英] Remove HTML scrollbars but allow mousewheel scrolling

查看:45
本文介绍了删除 HTML 滚动条但允许鼠标滚轮滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<块引用>

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

我可以通过设置 CSS 属性 overflow-y: hidden 来禁用网格中的垂直滚动条.但是,这也取消了使用鼠标滚轮滚动内容的功能.

有没有办法不显示滚动条但仍然允许通过鼠标滚轮或箭头键滚动内容?

解决方案

有Javascript方法,看你复制的帖子.

更好的解决方案是将目标 div 设置为 overflow:scroll,并将其包裹在第二个窄 8px 的元素中,即 overflow:hidden.

目标元素将有一个隐藏的滚动条.鼠标滚轮会起作用,但不会显示滚动条.

我的鼠标滚轮可滚动内容在这里....

请注意,滚动条的宽度为 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屋!

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