【问题标题】:Vertical Scroll is not working in iOS Devices Hammer.js垂直滚动在 iOS 设备 Hammer.js 中不起作用
【发布时间】:2016-01-09 11:41:00
【问题描述】:

使用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>

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

【问题讨论】:

    标签: javascript hammer.js


    【解决方案1】:

    垂直滚动:

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

    水平滚动:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-21
      • 2017-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多