How many pixels are scrolled on a website with a m

2020-08-24 03:31发布

问题:

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:

回答1:

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.



回答2:

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



回答3:

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/



回答4:

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.



回答5:

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

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



回答6:

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.