通过鼠标滚轮按下事件在网站上滚动了多少像素?

发布于 2024-12-09 22:31:55 字数 209 浏览 1 评论 0原文

我正在编写一个自定义滚动条并捕获 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:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

云雾 2024-12-16 22:31:55

许多鼠标驱动程序允许您设置鼠标滚轮滚动的距离,因此没有标准距离。我会尝试你的代码一段时间,并选择一个距离,让你不会整天滚动,但每次滚动时都不会跳一英里。你需要“感觉”一下。让朋友提供反馈,让几只手接触这种东西会有所帮助。

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.

梦巷 2024-12-16 22:31:55

我注意到在 Google Chrome 中 - 每次鼠标滚动 100px

I have noted that in Google Chrome - that is 100px per mouse scroll

梦里人 2024-12-16 22:31:55

对于 Firefox,您有 MozMousePixelScroll 事件,该事件报告应在 e.detail 中滚动的像素数。

window.addEventListener('MozMousePixelScroll', function(e) {
    console.log(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 in e.detail.

window.addEventListener('MozMousePixelScroll', function(e) {
    console.log(e.detail);
});

For many other browsers, you have the mousewheel event that reports e.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/

慵挽 2024-12-16 22:31:55

您需要在滚动之前存储当前的滚动位置,然后当您检测到滚动时获取我认为的移动距离。

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.

终陌 2024-12-16 22:31:55

我们可以使用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/

纵情客 2024-12-16 22:31:55

通常,每个鼠标滚轮“刻度”对应于一些可配置(由用户)的像素数。

例如,在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文