Pinch event with Hammer.js and touch emulator

I am trying to detect a pinch event using Hammer.js and a touch emulator in Chrome on the desktop. It can detect panning and not touch problems, but the pinch does not seem to respond. Change code code to codepen here: http://codepen.io/anon/pen/NqWymK

In case you are not familiar with the touch emulator, the pinch event should be modeled by holding down the shift key and clicking with the mouse.

(HTML)

<script src="http://cdn.rawgit.com/hammerjs/touchemulator/master/touch-emulator.js"></script>
<script>
  TouchEmulator();
</script>
<script src="https://hammerjs.imtqy.com/dist/hammer.js"></script>

<div id="myElement"></div>

(CSS)

#myElement {
  background: silver;
  height: 300px;
  text-align: center;
  font: 30px/300px Helvetica, Arial, sans-serif;
}

(Js)

var myElement = document.getElementById('myElement');

// create a simple instance
// by default, it only adds horizontal recognizers
var mc = new Hammer(myElement);

// listen to events...
mc.on("pinch pan tap", function(ev) {
myElement.textContent = ev.type +" gesture detected.";
});

Any ideas?

thank

+4
source share
2 answers

We came up with the following for testing. Added the following to mc.on (etc.):

mc.add(new Hammer.Pinch({ threshold: 0, pointers: 0 }));

.

, , , , . - , , .

+6

pinch - .

var hammertime = new Hammer($('#touchDiv')[0], {});

hammertime.get('pinch').set({ enable: true });
hammertime.on('pinch', function(ev) {
    console.log('zoom ' + ev.scale);
});
0

All Articles