5

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

Daniel
  • 597
  • 11
  • 19
  • Are you talking about Chrome Desktop, Chrome for Android / iOS? Multitouch panning in hammer.js 2.0.4 works for me more or less in all Chrome Versions (Desktop, Android). Hammer.js 2.0.4 has some issues with jumping `ev.deltaXY` (multitouch panning) values and one issue with `panstart` though (if that's what you are talking about), but there are workarounds for both of them until these are fixed. – mrksbnch Mar 12 '15 at 23:42
  • 1
    How did you manage to configure 2 pointers for the pan event? I have tried everything but to no avail. Could you please help me here? – myTerminal Apr 29 '15 at 10:36

1 Answers1

2

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
        };
      });
saike
  • 906
  • 8
  • 15
  • Thanks for that! I've used `e.scale` too discriminate between two finger panning and scaling. It's not perfect (you get a little bit of panning until you hit the scaling threshold) but still great. – Daniel Buckmaster Sep 12 '17 at 07:22
  • I don't understand this answer. Could you explain how you distinguish between panning and zooming? In your pinch callback it appears that you only pan, not zoom. – Michael Feb 18 '18 at 20:33
  • Hello, Mike. Unfortunately i have not enough time to explain, but i can copy a full source of my touch sensor, hope it will help you: https://pastebin.com/Xk4AmcdC – saike Feb 19 '18 at 09:03