在jquery mobile中垂直滚动期间触发swipeleft/swiperight

use*_*389 8 android jquery-mobile jquery-events

问题是当我想要垂直滚动时触发swipeleft/swiperight事件.

我们使用的是jquery mobile 1.1.0版本和jquery 1.7.1.

和代码是:

 $(document).delegate('#quizResumePage', 'swipeleft swiperight', function (event) {
   event.stopImmediatePropagation();
    if (event.type == 'swipeleft') {
       $('#btnnext').trigger('click');
    }  else  if (event.type == 'swiperight')  {
       $('#btnprevious').trigger('click');
    }
   event.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)

那么为什么当我想要翻页时滑动事件触发器?

这个问题发生在三星galaxy android 2.3.5 ...

任何人都可以帮我解决这个问题吗?

提前致谢...

roy*_*jas 12

您可以控制滑动事件的工作方式,以更改以下对象的值

$.extend($.event.special.swipe,{
  scrollSupressionThreshold: 10, // More than this horizontal displacement, and we will suppress scrolling.
  durationThreshold: 1000, // More time than this, and it isn't a swipe.
  horizontalDistanceThreshold: 30,  // Swipe horizontal displacement must be more than this.
  verticalDistanceThreshold: 75,  // Swipe vertical displacement must be less than this.
});
Run Code Online (Sandbox Code Playgroud)

在听滑动之前将它放在你的代码上.例如,将verticalDistanceThreshold更改为15,将durationThreshold更改为500,这将有助于减少误报.

另一方面,在您的代码中,您触发了按钮上的click事件,而当有效时,更好的方法是直接调用执行下一个/上一个操作的方法.

祝好运!

  • 将`horizo​​ntalDistanceThreshold`设置为`Math.min($(document).width()/ 2,160)`为我工作.来自[here](http://c-sharp-snippets.blogspot.com.ar/2011/12/jquery-mobile-swiperight-too-sensitive.html) (3认同)