3

I recently upgraded to hammer.js 2 and one of the first things a I noticed was that "hold" has been replaced with "press".

My old code worked fine with event delegation, but switching to press only seems to work when I put it on a specific element.

Note: I use hammer.js through the jquery plugin

Hammer.js 1

$(element).hammer().on("hold",callback);

Works fine

$(rootElement).hammer().on("hold",".elementSelector",callback);

Works fine

Hammer.js 2

This

$(element).hammer().on("press",callback);

works fine, while this

$(rootElement).hammer().on("press",".elementSelector",callback);

does not. The callback is never fired.

Jools
  • 839
  • 8
  • 22
  • did you get this to work? I'm facing the same problem – Haseeb Aug 24 '14 at 20:56
  • Not exactly, but I'm currently using a work around where I just put the listener on the root element, without a delegation selector and use my own function to figure out whether the inner element that triggered the event was one of (or the child of one of) the desired elements. I gave the code in [this answer](http://stackoverflow.com/a/25450384/514793) – Jools Aug 25 '14 at 22:12

1 Answers1

5

Hammer events have been simplified for speed in the new version. To reenable event delegation, just add domEvents:true as an option:

$(rootElement).hammer({domEvents:true}).on("press",".elementSelector",callback);
dadThrowsBolts
  • 356
  • 2
  • 11