通过鼠标滚轮按下事件在网站上滚动了多少像素?
我正在编写一个自定义滚动条并捕获 mousewheel
事件。我使用它来调整我想要滚动的元素的scrollTop。
向下滚动的像素数是否有标准,或者因系统而异?
我在最新版本的 Firefox 中显示 114px:
I'm working on writing a custom scrollbar and am catching the mousewheel
event. I'm using this to then adjust the scrollTop of the element I want to scroll on.
Is there a standard number of pixels that are scrolled down, or does it vary from system to system?
I'm showing 114px in the latest build of Firefox:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
许多鼠标驱动程序允许您设置鼠标滚轮滚动的距离,因此没有标准距离。我会尝试你的代码一段时间,并选择一个距离,让你不会整天滚动,但每次滚动时都不会跳一英里。你需要“感觉”一下。让朋友提供反馈,让几只手接触这种东西会有所帮助。
Many mouse drivers let you set the distance scrolled by the mouse wheel, so there is not a standard distance. I'd try your code out for a while and pick a distance that keeps you from scrolling all day but doesn't jump a mile at each scroll. You'll kind of need to "feel" it out. Get friends to give feedback, it helps to let a few hands touch this kind of thing.
我注意到在 Google Chrome 中 - 每次鼠标滚动 100px
I have noted that in Google Chrome - that is 100px per mouse scroll
对于 Firefox,您有
MozMousePixelScroll
事件,该事件报告应在e.detail
中滚动的像素数。对于许多其他浏览器,您有
mousewheel
事件报告e.wheelDeltaY
,但它们不是以像素为单位,您必须猜测要滚动的量。另请参阅 SproutCore 如何在自己的框架中处理滚动(他们也在编写自己的滚动视图): http://blog.sproutcore.com/scrolling-in-sproutcore/
For Firefox, you have the
MozMousePixelScroll
event, which reports the number of pixels that should be scrolled ine.detail
.For many other browsers, you have the
mousewheel
event that reportse.wheelDeltaY
, but they are not in pixels and you will have to guess the amount to be scrolled.Also see how SproutCore handles scrolling in their own framework (they're writing their own scrolling view too): http://blog.sproutcore.com/scrolling-in-sproutcore/
您需要在滚动之前存储当前的滚动位置,然后当您检测到滚动时获取我认为的移动距离。
You'll need to store the current scroll position before the scroll and then when you detect a scroll get the distance travelled me thinks.
我们可以使用javascript来控制。
请参阅下面的链接。我希望它能帮助你。
http://deepport.net/archives/javascript-scrolling/
We can controll using javascript.
Refer below link. I hope it will help you.
http://deepport.net/archives/javascript-scrolling/
通常,每个鼠标滚轮“刻度”对应于一些可配置(由用户)的像素数。
例如,在 Windows 中,每次鼠标滚轮单击滚动的距离应该是以下函数
SystemParametersInfo( SPI_GETWHEELSCROLLLINES, ...)
参数。此处您可以找到有关该主题的更多信息。
Usually each mouse wheel "tick" corresponds to some configurable (by user) number of pixels.
In Windows for example distance scrolled by each mouse wheel click should be a function of
SystemParametersInfo( SPI_GETWHEELSCROLLLINES, ...)
parameter.Here you can find more info on the subject.