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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7763326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 01:13:36  来源:igfitidea点击:

How many pixels are scrolled on a website with a mouse wheel down event?

javascriptjqueryeventsjavascript-eventsmouseevent

提问by Kirk Ouimet

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.

我正在编写自定义滚动条并捕获 mousewheel 事件。我正在使用它来调整我想要滚动的元素的 scrollTop。

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:

我在最新版本的 Firefox 中显示 114px:

enter image description here

在此处输入图片说明

回答by Surreal Dreams

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.

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

回答by Thompson

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

我注意到在谷歌浏览器中 - 每个鼠标滚动 100 像素

回答by Thai

For Firefox, you have the MozMousePixelScrollevent, which reports the number of pixels that should be scrolled in e.detail.

对于 Firefox,您有一个MozMousePixelScroll事件,它报告应该在e.detail.

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

For many other browsers, you have the mousewheelevent that reports e.wheelDeltaY, but they are not in pixels and you will have to guess the amount to be scrolled.

对于许多其他浏览器,您有mousewheel报告的事件e.wheelDeltaY,但它们不是以像素为单位,您必须猜测要滚动的数量。

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/

另请参阅 SproutCore 如何在自己的框架中处理滚动(他们也在编写自己的滚动视图):http: //blog.sproutcore.com/scrolling-in-sproutcore/

回答by griegs

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.

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

回答by griegs

We can controll using javascript. Refer below link. I hope it will help you.

我们可以使用javascript进行控制。请参考以下链接。我希望它会帮助你。

http://deepport.net/archives/javascript-scrolling/

http://deepport.net/archives/javascript-scrolling/

回答by c-smile

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.

例如在 Windows 中,每次鼠标滚轮点击滚动的距离应该是SystemParametersInfo( SPI_GETWHEELSCROLLLINES, ...)参数的函数 。

Hereyou can find more info on the subject.

您可以在此处找到有关该主题的更多信息。