用Hammer.js和.on()绑定事件 [英] Binding events with Hammer.js and .on()

查看:384
本文介绍了用Hammer.js和.on()绑定事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hammer.js 为我的Web应用程序添加了javascript触摸和手势支持.我的问题在于将.hammer()与DOM元素一起使用,直到准备好对文档进行.ajax()调用之前,DOM元素才存在.

Hammer.js adds javascript touch and gesture support to my web app. My problem lies in using .hammer() with DOM elements that do not exist until an .ajax() call on document ready.

以前,我使用过类似的东西:

Previously, I've used something like:

$('#parent').on('click', '.child', function(e){
    $(this).hammer()...
});

但是,我需要能够在不调用.on()的情况下将事件与Hammer绑定,因为.on()事件类型与Hammer事件类型不匹配.感谢您的帮助-我绝不是jQuery的天才,我也不是很熟悉事件绑定.

But, I need to be able to bind the event with Hammer without calling .on() as the .on() event types do not match the Hammer event types. Any help is appreciated - I'm by no means a jQuery genius, nor am I very familiar with event binding.

推荐答案

查看 jquery.hammer.js 源代码,委派事件应该没有问题.

Looking at the jquery.hammer.js source, you should have no problem delegating events.

$("#parent").on("doubletap",".child",dostuff);

只需确保在将元素添加到页面时调用元素上的.hammer().

just make sure you call .hammer() on the elements when you add them to your page.

这篇关于用Hammer.js和.on()绑定事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆