Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if user is scrolling with trackpad?

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 :)

like image 937
Cody Avatar asked Sep 18 '12 22:09

Cody


People also ask

How do I know my user scroll?

window. onscroll = function() { var distanceScrolled = document. documentElement. scrollTop; if (distanceScrolled > 112) { do something... } }

Why is Scrolling with touchpad not working?

Enable via Settings app Choose Touchpad from the menu in the left side pane. Locate the Scroll and zoom section. Here, make sure that the box next to Drag two fingers to scroll is checked. If the box is empty, simply click on it to enable it.

How do I fix my touchpad Scrolling fast?

Open the Settings menu by pressing the Windows key, + I. Click on Devices. On the Devices screen, select Touchpad in the left-hand column. If your laptop has a precision touchpad, you can use the slider marked Change the cursor speed on the right.


2 Answers

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.
});
like image 78
Yoann Avatar answered Sep 19 '22 14:09

Yoann


No, this is not possible. The only solution I can think of is set a limit on the scrolling speed. I'm not going to try and decipher your code but I'd recommend making a timedOut variable initialized to zero which is set to one every time you scroll to a new image. Use a setTimeout() to set it back to zero after, say, 50ms. Before you scroll to a new image, check this timedOut variable and only scroll if it's zero. (Make sure you place your setTimeout inside of the timedOut check, otherwise it will be constantly called every time the mousewheel moves, which is not what you want.)

like image 28
HellaMad Avatar answered Sep 19 '22 14:09

HellaMad