Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-Touch Panning with Hammer.js

I'm having difficulties implementing multi-touch panning with hammer.js. Panning events are only fired with single pointers. If I try to drag with two fingers it does not fire until I release at least one finger. Do I have to do something special to the hammer configuration?

EDIT: I already found that I can configure 2 pointers for the pan event, but now I see that Chrome has a built-in feature to open a context menu on two-finger tap, which most of the time prevents the panning from being recognized. If I simply catch the 'contextmenu' event and call preventDefault(), it will (obviously) completely disable the pan recognizer. Any other way?

BR, Daniel

like image 902
Daniel Avatar asked Oct 31 '22 09:10

Daniel


1 Answers

You should use 'pinch' event. For two-fingers panning and zooming. PINCH event has property: 'pointers', with finger events;

    var previous_pinch_delta = {
      x: 0,
      y: 0
    };
    hammered.on('pinch', function(e){
        camera.pan(e.deltaX-previous_pinch_delta.x, e.deltaY-previous_pinch_delta.y);
        previous_pinch_delta = {
          x: e.deltaX,
          y: e.deltaY
        };
      });
like image 137
saike Avatar answered Nov 09 '22 12:11

saike