我正在使用HammerJS v2.0.4(独立 - 没有Hammer jQuery插件)。我希望有一个带有自己参数的回调函数。我不知道如何将自定义参数传递给手势回调函数。这是我想要做的(没有自定义参数):
// get hammer fuction
function getGesture(element){
// instantiate hammer - $(this).get[0] gives me a <div>
var gesture = new Hammer.Manager($(this).get[0]);
// add hammer gestures
gesture.add(new Hammer.Pan({ threshold: 0, pointers: 0 }));
gesture.add(new Hammer.Swipe()).recognizeWith(gesture.get('pan'));
// gesture and callback without custom parametr
gesture.on('panstart panmove', this.panRecognizer);
// But I wanted something like
// gesture.on('panstart panmove', this.panRecognizer, this)
// where 'this' is a custom parameter
gesture.on('swipe', this.swipeRecognizer); // same as above
}
function panRecognizer(ev, self){
// do something with self and ev
}
function swipeRecognizer(ev, self){
// do something with self and ev
}
有人可以帮我这个吗?我是JS的新手