【问题标题】:Hammer.js swipe stop vertical scroll ipadHammer.js 滑动停止垂直滚动 ipad
【发布时间】:2014-02-26 21:38:36
【问题描述】:

我正在开发一个滑动页面功能,我使用锤子的 swiperight 和 swipeleft 事件在有效的部分之间滑动。但是在触摸设备(ipad)上,当你滑动时,它也会水平滚动,这很烦人。因此,当我使用 jquery .animate() 时,动画有时并不流畅,即它直接跳转到下一页/上一页而不是动画。我的代码在下面

有没有办法在滑动时停止 ipad 水平滚动?我知道 eventDefault() 可以,但它对我不起作用

      Hammer(array[i]).on("swipeleft", function(e) {
//e.preventDefault(); -- this doesnt work :(
        if(!$(this).next().length){
          console.log("no more pages to right");
        }
        else{
          $(this).next().animate({
              marginLeft:"auto"
          },{duration:500,queue:false});

          $(this).animate({
            marginLeft:"-" + windowWidth + "px"
          },{duration:300,queue:false});
        }
      });

      Hammer(array[i]).on("swiperight", function() {
        if(!$(this).prev().length){
          console.log("no more pages to left");
        }
        else{
          $($(this)).animate({  
            marginLeft:windowWidth+"px"
          },{duration:300,queue:false}); 

          $($(this).prev()).animate({
              marginLeft:"0px"
          },{duration:400,queue: false});
        }
      });

【问题讨论】:

    标签: javascript jquery ipad hammer.js


    【解决方案1】:

    在研究文档 (https://github.com/EightMedia/hammer.js/wiki/Tips-&-Tricks) 之后,我发现了 e.gesture.preventDefault()。所以我把它应用到了该部分所在的容器中。

      $("#container").on("dragright dragleft",function(e){
        e.gesture.preventDefault();
      }); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-03
      • 1970-01-01
      • 2012-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-08
      • 1970-01-01
      相关资源
      最近更新 更多