hammer.js swipe disabling native pinch to zoom

最后都变了- 提交于 2019-12-12 19:11:20

问题


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:


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.



来源:https://stackoverflow.com/questions/35141653/hammer-js-swipe-disabling-native-pinch-to-zoom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!