Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Predictive Scrolling - Mousewheel (OnScroll) Event fires too often (Touchpad)

I am executing Javascript onScroll. My code works great with any normal computer mouse, but when I use my notebook's touchpad, I encounter the following situation:

  • my mouse fires (about 1 to 8) mousewheel events while the finger is moving the wheel.
  • my touchpad fires a lot more (~60) mousewheel events while the two fingers are touching the pad and continues to fire after my fingers are up in the air again.

I know this behavior from mobile touch devices. The Feature is called "Predictive Touch" - The Scrolling continues if your finger movement had enough acceleration before lifting it up.

I think the touchpad drivers are setting this "smooth scrolling" behavior.

To debug this case, I have used the following code:

/* Handle Mouse-Wheel Scrolling */
var lastChange = +new Date();
$(window).bind('mousewheel',    function(e){
    console.log("mw");
    if(+new Date() - lastChange > 1000){
        console.log("mw allowed");
        if(e.originalEvent.wheelDelta > 0)  {/*go to previous*/}
        else{   /*go to next*/}
        lastChange = +new Date();
    }
return false;});

This is a simple code that "allows" a mouse-scrolling-event every second.

If I make a fast touchpad-scroll, the mousewheel event is fired ~300 times. The one-second-condition is letting 3 events happen. My fingers were on the touchpad for far less than a second.

With this test, I discovered that the mousewheel events are still fired (almost continuously for 3 seconds), even when my fingers are already off the touchpad.

Is there a Javascript function or a workaround / trick / hack to avoid this behavior?

Something like a onTouchEnd event for touchpads, maybe?

like image 791
GlabbichRulz Avatar asked Jan 16 '16 19:01

GlabbichRulz


1 Answers

To achieve this, you'd have to distinguish between mouse scroll events and touchpad events, which is not (yet) possible using JavaScript. It was already asked in question How to capture touch pad input.

Pointer Events are currently in state of Editor's Draft and not yet supported by any browser. See also touch events docs on MDN.

like image 160
Michał Perłakowski Avatar answered Nov 10 '22 04:11

Michał Perłakowski