How do you delegate events in hammer.js version 2.0?

In hammer.js v1.x (with the jquery plugin) you can delegate the following events:

$('ul').hammer().on("touch", "li", callback);

Using this syntax, you can attach an event listener to ulinstead of the individual lielements you want to listen to. This will allow you to dynamically add elements lito ulwithout reconnecting event listeners.

However, I cannot figure out how to do this in Hammer v2.0. (I changed touchto tapfor the new syntax).

+4
source share
2 answers

, . , domEvents :

$('ul').hammer({domEvents:true}).on("tap", "li", callback);
+5

( () jquery hammer.js 2 ).

. , , , /, , . li, li, div.

:

function _isDelegate(selector, target, currentTarget) {

   var delegate = null;

   while (target && target != currentTarget) {
      delegate = $(target).filter(selector)[0];
      if (delegate) 
         return delegate;
      target = target.parentNode;
   }

   return delegate;

}

selector - , . "". target - , . , . currentTarget - parent/root, .

null, li, , li, .

0

All Articles