Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 548
Kirk Ouimet Avatar asked Oct 14 '11 05:10

Kirk Ouimet


4 Answers

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.

like image 81
Surreal Dreams Avatar answered Oct 06 '22 01:10

Surreal Dreams


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

like image 28
Thompson Avatar answered Oct 06 '22 01:10

Thompson


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/

like image 22
Thai Avatar answered Oct 06 '22 01:10

Thai


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.

like image 31
griegs Avatar answered Oct 05 '22 23:10

griegs