我正在开发这个小网站:Website ;我正在使用 HammerJS 作为触摸支持库。
它似乎在响应事件,并且识别 event.type
属性,但是当我试图获取 event.direction
或其他相关drag
事件的属性控制台中没有任何输出(我在控制台中记录结果)。
这就是我监听 drag
事件的方式 "
Application.ApplicationController.prototype.Drag = function(selector, delay, callback) {
return $(selector).on('drag', _.debounce(function(event){
event.preventDefault();
return (typeof callback === 'function' && callback !== undefined) ? callback.apply( event, [ event ] ) : 'Argument : Invalid [ Function Required ]';
}, delay));
};
我这样调用它:
this.Drag(selector, delay, function(event) {
console.log(event.type, event.direction);
});
有人可以告诉我我在那里做错了什么或者我是否遗漏了什么吗?
编辑:我刚刚替换了 jQuery 库:jquery.specialevents.hammer.js ;与旧jquery.hammer.js ;现在它似乎正在响应所有事件,我得到了我应该得到的所有属性。我仍然想知道为什么我尝试使用的那个不起作用?
编辑: 我找到了我的问题的根本原因,我的代码依赖于一些库,我正在使用 Yepnope 脚本加载器异步加载这些库,所以一路上的某个地方而不是加载所有库(包括 hammer.js 的 jquery 插件),其中一些丢失了 :) 我已经解决了这个问题,现在事件具有它们应该具有的属性。
最佳答案
Still I would like to know why isn't the one I tried to work with working ?
了解 jquery.specialevent.hammer.js
和 jquery.hammer.js
之间的区别应该有助于理解问题。 Damien, the creator of jquery.specialevent.hammer.js
, explains why .
However Eight Media decided to create their own namespace in jQuery to activate the events.
$("#element").hammer({ /* options */ }).on("tap", function(ev) { console.log(ev); });
So in the end they are not using the default jQuery eventing system. That means my existing source code which used jQuery mobile events has to be change. That’s why I decided to implement the use of Hammer.JS with the jQuery special eventing API.
$("#element").on("tap", { /* options */ }, function(ev) { console.log(ev); });
I put jquery.specialevent.hammer.js onto my Github where you can also find a demo. Maybe Eight Media accepts my pull request and it will be part of Hammer.JS.
关于javascript - HammerJS 事件属性未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14186851/