我正在使用pinchinpinchoutpinchend。如果是长pinchinpinchout,则pinchend可以触发,但是如果是短pinchinpinchout,则不会触发。是错误还是我做错了什么?

gestos = new Hammer.Manager(document.body, {
    touchAction: "manipulation"
});
gestos.add(new Hammer.Pinch({event: 'pinch'})); // If it isn't added, pinchout and pinchend never fires
gestos.add(new Hammer.Pinch({event: 'pinchin'}));
gestos.add(new Hammer.Pinch({event: 'pinchout'}));
gestos.add(new Hammer.Pinch({event: 'pinchend'}));
gestos.on("pinchin pinchout pinchend", function (e) {
    if (e.type == "pinchin")
        interact("#mapa").resizable(false);
    else
        interact("#mapa").resizable(true);
    console.log(e.type);
});

最佳答案

gestos.add(new Hammer.Pinch({event: 'pinchcancel'}));
gestos.on("pinchin pinchout pinchend pinchcencel", function (e) {
    if (e.type == "pinchin")
        interact("#mapa").resizable(false);
    else
        interact("#mapa").resizable(true);
    console.log(e.type);
});
//sometimes the device just recognize our move as pinchcancel when we actually want to fire pinchend event.

关于javascript - Hammer JS:Pinchend有时不会触发,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36521123/

10-12 13:14