垂直滚动在iOS设备Hammer.js中不起作用

时间:2016-01-09 11:41:01

标签: javascript hammer.js

使用hammer.js(v 2.0)我尝试触发pandown手势的事件,但是当我应用手势事件的元素具有比浏览器布局高度更多的内容时,默认滚动停止,请参阅此codepen http://codepen.io/shmdhussain/pen/GomRVw#0



var myElement = document.getElementById('myElement');
var myElement1 = document.getElementById('myElement1');
// create a simple instance
// by default, it only adds horizontal recognizers
var mc = new Hammer(myElement);

// let the pan gesture support all directions.
// this will block the vertical scrolling on a touch-device while on the element
mc.get('pan').set({ direction: Hammer.DIRECTION_ALL });

// listen to events...
mc.on("panleft panright panup pandown tap press", function(ev) {
    myElement1.textContent = ev.type +" gesture detected.";
});

#myElement {
  background: silver;
  height: 300px;
  text-align: center;
  font: 30px/300px Helvetica, Arial, sans-serif;
}

<script src="https://hammerjs.github.io/dist/hammer.js"></script>

<div id="myElement">
  <p id="myElement1">hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
 <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
 <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
 <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
 <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
 <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
 <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
 <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
 <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>
   <p>hekko</p>

</div>
&#13;
&#13;
&#13;

在iOS设备iPhone中发生问题(在带有iOS 8.4.1的iPhone 6Plus上测试)

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。一旦我添加了Hammer.Swipe识别器,垂直滚动就无法在iOS中运行。

答案 1 :(得分:0)

垂直滚动:

let mc = new Hammer.Manager(element, {
    touchAction: "pan-x"
  });

水平滚动:

let mc = new Hammer.Manager(element, {
            touchAction: "pan-y"
          });

检查此链接: http://hammerjs.github.io/touch-action/