swipeleft/swiperight triggered during vertical scroll in jQuery mobile

强颜欢笑 提交于 2019-12-12 08:03:05

问题


Problem is that swipeleft/swiperight event is trigger when I want vertical scroll.

We are using jQuery mobile 1.1.0 version and jQuery 1.7.1.

and code is:

 $(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();
});

Then why swipe event trigger when I want to scroll the page?

This problem is occur in the Samsung galaxy android 2.3.5...

Can any one help me for this issue?


回答1:


You can control how the swipe event works changing the values of the following object

$.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.
});

place it on your code before listening to the swipes. Change for example the verticalDistanceThreshold to 15 and the durationThreshold to 500 that will help to reduce the false positive.

On the other side, in your code you're triggering the click event on your buttons, while that works, a better approach would be to call directly the method that executes next/previous actions.

Good luck!



来源:https://stackoverflow.com/questions/11290771/swipeleft-swiperight-triggered-during-vertical-scroll-in-jquery-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!