Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HammerJS continuous dragging (drag after release)

Can I achieve dragging after release with HammerJS (and how...)? (I use it alongside AngularJS but that shouldn't matter)

The reason I am asking is that I want to achieve smooth scrolling (like native iOS continued scrolling after release of the finger)

I am sure this can be done somehow because there is a velocity property in the event of the gesture.

my code has a overlay div on top of my content that detects the touches, and then I do manual control of the scrolling of the divs below based on that.

like image 575
veta Avatar asked Jan 02 '26 08:01

veta


1 Answers

You'll just need to set up your own velocity callback on panend. Something like the below should work (assuming using Hammer v2)

    var friction = -0.05;

    function panend(evt) {
        applyVelocity(evt.velocityY,evt.direction);
    }

    function applyVelocity(v,dir) {
        var dist = v*16;
        if(dir===Hammer.DIRECTION_DOWN) {
            dist*=-1;
        }

        //code here to move your elements Y transform

        if(v>0) {
            v+=friction;
            window.requestAnimationFrame(function(){
                applyVelocity(v,dir);
            });
        }
    }
like image 141
Citizen Avatar answered Jan 03 '26 22:01

Citizen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!