3

Is it possible to use the native "pinch to zoom" on touch devices while using hammerjs to recognize swipe gestures?

I want users to be able to zoom in on images in the gallery (as they can natively when hammer event handler is not bound) and swiping to display the previous or next image.

hammertime.on('swipe', function(ev) {
    if (ev.direction === 2) {
        nextImage();
    } else if (ev.direction === 4) {
        prevImage();
    }
});

1 Answer 1

3

Solution was to use touchAction = 'auto'

var hammertime = new Hammer(galleryEl, {touchAction : 'auto'});

Before doing this be sure to read http://hammerjs.github.io/touch-action/

When you set the touchAction to auto it doesnt prevent any defaults, and Hammer would probably break. You have to call preventDefault manually to fix this. You should only use this if you know what you're doing.

1
  • 6
    Hmph. Well I don't know what I'm doing, all I know after reading that page is that I apparently can either lose pinch to zoom or I can break hammerjs. It would be helpful if I knew exactly what I had to do to unbreak hammerjs!
    – Michael
    Commented Feb 18, 2018 at 2:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.