Check if user is scrolling with trackpad?

Cody picture Cody · Sep 19, 2012 · Viewed 25.3k times · Source

I have created a site where users are able to scroll through a gallery using mouse scroll or arrow up/down. It is working like I want it to, and changing one image pr scroll when scrolling with a mouse. But if the user is scrolling with a trackpad it is almost impossible to scroll a single image at a time.

So my question is: Is there a way to check if the user is scrolling by trackpad, and then changing the behavior of the scrolling, so it becomes less sensitive, and thereby easier to scroll a single image at a time?

I am not very good at jquery, my solution so far has been put together from a couple of scripts:

http://jsfiddle.net/MukuMedia/PFjzX/33/

Hope someone can help me :)

Answer

Yoann picture Yoann · May 22, 2013

I found out that the magic number here was 40.

It seems that with the trackpad (probably with the magic mouse too) the delta get increased 40 times.

And it stays that way even if you take back your normal mouse and scroll with it later.

So what I did, using the jquery mousewheel plugin :

b.mousewheel(function(evt,delta,deltaX,deltaY){
    if(Math.abs(deltaY)>=40)
        deltaY/=40;
    if(Math.abs(deltaX)>=40)
        deltaX/=40;

    //Do your stuff here.
});