specious / cloud9carousel

:cyclone: 3D-perspective carousel for jQuery / Zepto
http://j.mp/cloud9demo
233 stars 88 forks source link

Problematic "mousewheel" scrolling characteristics using particular track pads #1

Open specious opened 10 years ago

specious commented 10 years ago

"Mouse wheel" scrolling is ridiculously sensitive and unmanageable when using track pads which send out many signals in quick succession (such as on the MacBook Pro). Unfortunately, since there appears to be no way to know directly what type of device is triggering the mousewheel events, it is not trivial to somehow normalise or "tame" the input from the track pad without also affecting the "1 tick per click" behaviour of the standard mouse wheel. @darsain has described the same phenomenon in this discussion at the sly.js project. Ideas are appreciated.

Here is a recording of a light swipe using two fingers on a MacBook Pro track pad:

c9-trackpad

The following is a recording of a down-scroll of 4 ticks using the mouse wheel on a USB mouse:

c9-mousewheel

dt is the time (in milliseconds) elapsed since the last event.

specious commented 10 years ago

I had some success taming the response to the track pad on my MacBook Pro with:

      if( options.mouseWheel ) {
        var t;
        var tLast = 0;
        var tReset = 120;
        var dt;
        var d = 0;

        container.bind( 'mousewheel.cloud9', function( event, delta ) {
console.log( "====== delta: " + delta )
          t = new Date();
          dt = t - tLast;
          tLast = t;
console.log( "=== dt: " + dt )

          if( dt > tReset ) {
            d = 0;
            self.go( (delta > 0) ? 1 : -1 );
          } else {
            d += Math.log( Math.abs( delta ) * 20 );

            if( Math.abs( d ) > 40 ) {
              d = 0;
              self.go( (delta > 0) ? 1 : -1 );
            }
          }

          return false;
        } );
      }

However, that of course distorts the response to a standard well-behaving mouse wheel. Attempting to determine the nature of the input device would be easy if the track pad didn't emit deltas of magnitude 1 among other potential values.

Any ideas?