使用jQuery Mobile更改滑动灵敏度

时间:2013-05-16 04:19:30

标签: jquery mobile swipe

我遇到了iPhone的问题,并刷到其他页面。向下滚动页面时,动作的灵敏度很敏感,并将滑动到下一页。有没有办法在此代码中控制滑动灵敏度:

<script type="text/javascript">
$(document).ready(function(){
    var counter = 1;
    $(document).bind('swipeleft','#deal_1',function (event, ui) {
    counter++;
    if(counter>3)
    counter = 1;
    var nextpage = 'dailydeal'+counter+'.html';
    if (nextpage.length > 0) {
        $.mobile.changePage(nextpage, {transition: "slide",
        reverse: false}, true, true);
        }
    });
 $(document).bind('swiperight','#deal_1',function (event, ui) {
     counter--;
     if(counter<1)
     counter=3;
     var prevpage = 'dailydeal'+counter+'.html';
     if (prevpage.length > 0) {
         $.mobile.changePage(prevpage, {transition: "slide",
         reverse: true}, true, true);
     }
     });
  });
</script>

2 个答案:

答案 0 :(得分:20)

要定制对所有设备的响应,我建议设置相对于屏幕宽度的阈值。例如:

$.event.special.swipe.scrollSupressionThreshold = (screen.availWidth) / 60;
$.event.special.swipe.horizontalDistanceThreshold = (screen.availWidth) / 60;
$.event.special.swipe.verticalDistanceThreshold = (screen.availHeight) / 13;

请参阅jQuery Mobile API Documentation

答案 1 :(得分:7)

这似乎在很大程度上起作用:

<script type="text/javascript">
    $(document).bind("mobileinit", function () {
    $.event.special.swipe.horizontalDistanceThreshold = 100;
    });
</script>

根据我的理解,horizo​​ntalDistanceThreshold默认设置为30px,所以我将其更改为100.到目前为止,当向下滚动时,它似乎是平衡的,而且不会太敏感。

相关问题