cubiq / iscroll

Smooth scrolling for the web
http://iscrolljs.com
MIT License
12.87k stars 3.81k forks source link

Horizontal scroll on trackpads #679

Open pyronaur opened 10 years ago

pyronaur commented 10 years ago

iScroll currently doesn't support horizontal scroll with trackpad horizontal swiping movement. The horizontal scroll is jumpy depending whether your horizontal movement is more downwards or upwards oriented.

Ticket #523 lead me to the right direction, but is still missing logic that determines whether iScroll should use the mouseWheelX or mouseWheelY. This fixes the issue for me as far as I've tested it for the last 5 minutes.


        wheelDeltaX *= this.options.invertWheelDirection;
        wheelDeltaY *= this.options.invertWheelDirection;

        // 2 lines above haven't been modified
        // I left them for reference where the code below is

        // Note:
        // This is line ± 1085 for me in iscroll-probe.js
        // I've made other modifications
        if ( !this.hasHorizontalScroll ) {
            wheelDeltaX = 0;
        } else if ( !this.hasVerticalScroll && this.options.mouseWheelScrollsHorizontally ) {

            // If absolute DeltaX is less than absolute DeltaX
            // Replace DeltaX with DeltaY
            // Otherwise just remove DeltaY and use the actual DeltaX 
            if( Math.abs(wheelDeltaX) < Math.abs(wheelDeltaY) ) {
                wheelDeltaX = wheelDeltaY;  
            }
            wheelDeltaY = 0;

        } if ( !this.hasVerticalScroll ) {
            wheelDeltaY = 0;
        }

As in #523, modify approx. line 247 and add this.options.mouseWheelScrollsHorizontally

    this.options = {

        resizeScrollbars: true,

        mouseWheelSpeed: 20,
        mouseWheelScrollsHorizontally: true,  // this line was added

I hope this helps someone, or maybe, gets merged in some day.

marcj commented 8 years ago

Any news here?

durchanek commented 7 years ago

Thank you for posting this and +1 to merging!

jackocnr commented 6 years ago

I need this!