hammer.js object has no method addEventListener

和自甴很熟 提交于 2019-12-01 15:04:46
James Donnelly

I imagine your issue is that you don't have Hammer.js's jQuery Plugin installed (GitHub).

Because of this, you cannot pass a jQuery object into the Hammer() function, your two options:

With the jQuery Plugin

Add the jQuery Plugin I've linked to above to your project, then call:

$('#kaydir').Hammer(...)

Without the jQuery Plugin

Pass only the element into Hammer() and not the jQuery object, by using [0]:

Hammer(resim[0]).on(...)

Or instead change your resim variable to hold the result of calling JavaScript's getElementById.

var resim = document.getElementById('kaydir');
Hammer(resim).on(...)

If you are using jQuery, you should use the jQuery Hammer version and use it like that:

var resim = $("#kaydir");
resim.hammer().on("swipeleft", function(ev) {
    console.log('left: ', ev);
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!