【问题标题】:jquery mobile swipe delay?jquery移动滑动延迟?
【发布时间】:2015-07-12 17:58:30
【问题描述】:

我在实习期间尝试为移动应用实现简单的滑动。在我将它实施到我的项目之前,我首先做了一个例子。当我向左滑动时,我将被重定向到下一页。但是,当我尝试向右滑动以返回上一页时,我需要大约 4 次尝试才能返回。

index.html

      *{
        padding: 0;
        margin: 0;
    }

    div{
        max-width: 1024px;
        width: 100%;
        height: 768px;
        background: green;
    }


    <div></div>

     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4 
/jquery.min.js"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5
/jquery.mobile.min.js"></script>
<script>

    $("div").on("swipeleft",function(){
     window.location = "nextpage.html";
    });

    });

</script>

下一页.html

   *{
        padding: 0;
        margin: 0;
    }

     div{
        max-width: 1024px;
        width: 100%;
        height: 768px;
        background: blue;
    }

    <div></div>

     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4 
/jquery.min.js"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5
/jquery.mobile.min.js"></script>
<script>

    $("div").on("swiperight",function(){
     window.location = "index.html";
    });

    });

</script>

【问题讨论】:

  • 在你的 jquery 选择器中使用的div 可能会导致这种情况。尝试给最外层的 div 一个类,然后用它来委托swiperight 事件
  • labs.rampinteractive.co.uk/touchSwipe/demos/Basic_swipe.html: 你可以看看这个JS..也许对你有用
  • @Renboy - 我认为您缺少脚本块的第一行 $(document).ready(function () {....

标签: jquery jquery-mobile


【解决方案1】:

您是否尝试调整滑动阈值以使右侧滑动更灵敏?我猜这与您的右滑动略微倾斜或更短(可能刚好足以落在阈值之外)有关。

尝试在第二页的滑动处理程序之前添加以下行。如果您的滑动仍然无法识别,请尝试进一步更改阈值。

// this is the distance you have to drag your finger across to be recognized as a swipe - default is 30px. Decrease this.
$.event.special.swipe.horizontalDistanceThreshold = 10;
// this is the amount of vertical leeway you get before your horizontal swipe is NOT treated as a horizontal swipe - default is 75px. Increase this.
$.event.special.swipe.verticalDistanceThreshold = 100;
// this is the amount of time you get to drag your finger across and make the thresholds - default is 1000 = 1s. Increase this.
$.event.special.swipe.durationThreshold = 2000;

【讨论】:

  • 我使用了另一个库,但我下次会尝试,谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-10
相关资源
最近更新 更多