本文介绍了用jquery hammer.js 2和事件授权长按(按住)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近升级到hammer.js 2并且我注意到的第一件事之一是hold已被press取代。
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.
注意:我通过jquery插件使用hammer.js
Note: I use hammer.js through the jquery plugin
$(element).hammer().on("hold",callback);
工作正常
$(rootElement).hammer().on("hold",".elementSelector",callback);
工作正常
此
$(element).hammer().on("press",callback);
工作正常,而
$(rootElement).hammer().on("press",".elementSelector",callback);
没有。永远不会触发回调。
does not. The callback is never fired.
推荐答案
新版本中的Hammer事件已经简化了速度。要重新启用事件委派,只需添加domEvents:true作为选项:
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);
这篇关于用jquery hammer.js 2和事件授权长按(按住)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!