HuwD HuwD - 9 months ago 194
Javascript Question

Pinch event with Hammer.js and touch-emulator

Am trying to detect the pinch event using Hammer.js and the touch emulator in Chrome on desktop. Can detect pan and tap no problem but pinch doesn't seem to be responding. Have modified sample code on codepen here:

In case you aren't familiar with the touch-emulator the pinch event should be simulated by holding shift and clicking and dragging mouse.


<script src=""></script>
<script src=""></script>

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


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


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?


Answer Source

Have come up with following for testing purposes. Have added the following before the mc.on(etc....):

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

This removes the need for more than one touch point to trigger the multitouch.

As I understand it the touch-emulator should simulate more than one touch point but deosn't seem to be working. If anyone can tell why, that would be appreciated.