2016-01-09 52 views
0

使用hammer.js(v 2.0)我試圖觸發pandown手勢的事件,但是當我應用手勢事件的元素比瀏覽器具有更多內容時佈局高度,默認滾動停止時,看到這個codepen http://codepen.io/shmdhussain/pen/GomRVw#0垂直滾動不適用於iOS設備Hammer.js

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)

回答

1

我遇到同樣的問題。只要添加Hammer.Swipe識別器,iOS中的垂直滾動功能就無法運行。

+0

看到這個問題我發佈在hammerjs github頁面https://github.com/hammerjs/hammer.js/issues/902#event-510200753 –

+0

任何人都有這個解決方案嗎? – cgatian