Long press (hold) with jquery hammer.js 2 and event delegation

那年仲夏 提交于 2019-12-23 19:25:24

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/25134649/long-press-hold-with-jquery-hammer-js-2-and-event-delegation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!