在动态加载的内容上使用Hammer.js [英] Using hammer.js on dynamically loaded content
本文介绍了在动态加载的内容上使用Hammer.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为一个Web应用程序使用Hammer.js.
I'm playing around with hammer.js for a web app.
除了加载了ajax的内容外,我可以使它正常工作.
I can get it to work just fine, except on content loaded with ajax.
我为jquery使用了Hammer.js特殊事件插件.
I use the hammer.js special-events plugin for jquery.
以下可以正常工作:
$('#menu a').on("tap", function(event) {
//console.log(event);
});
但是当我使用jquery委托语法时:
But when I use the jquery delegation syntax:
$('body').on("tap", '#menu a', function(event) {
//console.log(event);
});
什么也没发生...
正确的语法是什么?
推荐答案
如果您动态添加a
元素,请尝试以下操作:
Try this if you dynamically add the a
element :
$('#menu').on("tap", 'a', function(event) {
//console.log(event);
});
或者这个:
$('#menu').hammer().on("tap", 'a', function(event) {
//console.log(event);
});
这篇关于在动态加载的内容上使用Hammer.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文