我想在我的phonegap / cordova app中加入hammer.js .
版本:Hammer.JS - v1.0.10 - 2014-03-28
但似乎这里的例子是:
http://rawgithub.com/EightMedia/hammer.js/master/examples/carousel.html
我的华为U8850 Android 2.3.5设备无效 . 问题:滑动事件未按预期触发 .
大约二十次尝试中只有一次是成功的 .
拖动工作正常 - 我不得不将页面拖到中点以进入下一页 .
使用库存浏览器,Opera mobile和cordova应用程序进行测试 .
对于cordova应用程序,我在hammer.js中添加了一些调试输出:
handler : function swipeGesture(ev, inst) {
if(ev.eventType == EVENT_END) {
// max touches
if(ev.touches.length < inst.options.swipe_min_touches ||
ev.touches.length > inst.options.swipe_max_touches) {
console.warn(' return'); // this is not the problem
return;
}
// when the distance we moved is too small we skip this gesture
// or we can be already in dragging
if(ev.velocityX > inst.options.swipe_velocity ||
ev.velocityY > inst.options.swipe_velocity) {
// trigger swipe events
console.log('IS TRIGGERED VX: ' + ev.velocityX + ' inst.options.swipe_velocity: ' + inst.options.swipe_velocity);
inst.trigger(this.name, ev);
inst.trigger(this.name + ev.direction, ev);
} else {
console.log('NOT TRIGGERED VX: ' + ev.velocityX + ' inst.options.swipe_velocity: ' + inst.options.swipe_velocity);
}
}
}
这是logcat输出:
NOT TRIGGERED VX: 0 inst.options.swipe_velocity: 0.7
NOT TRIGGERED VX: 0 inst.options.swipe_velocity: 0.7
NOT TRIGGERED VX: 0 inst.options.swipe_velocity: 0.7
NOT TRIGGERED VX: 0 inst.options.swipe_velocity: 0.7
NOT TRIGGERED VX: 0 inst.options.swipe_velocity: 0.7
NOT TRIGGERED VX: 0 inst.options.swipe_velocity: 0.7
NOT TRIGGERED VX: 0 inst.options.swipe_velocity: 0.7
NOT TRIGGERED VX: 0 inst.options.swipe_velocity: 0.7
IS TRIGGERED VX: 0.9742769115007959 inst.options.swipe_velocity: 0.7
SWIPE RIGHT
NOT TRIGGERED VX: 0 inst.options.swipe_velocity: 0.7
有趣的是:速度不仅太慢而且不能触发事件,大多数时候都是零 .