2015-12-18 33 views
0

我有兩個div,彼此相鄰。除了click事件,我添加了一個swiperightswipeleft做一些事情。但是當我添加這些事件時,在iPad上滾動不再起作用。在個人電腦上沒有問題!如何讓工作jquery在iPad上滾動「滑動」?

有沒有其他的方法可以使它們在iPad(觸摸屏設備)上相互兼容?

謝謝!

+0

你能告訴你已經嘗試了什麼至今? –

回答

0

實測值的溶液:

http://stephband.info/jquery.event.swipe/

滑動事件是建立在移動事件(stephband.info/jquery.event.move)的頂部上的薄包裝。默認情況下,移動事件會覆蓋原生滾動,因爲他們假定您想要移動某些內容而不是滾動窗口。要重新啓用滾動,請在movestart處理程序中調用e.preventDefault()。

在上面的例子中,我們希望能夠swipeleft和swiperight,但上下滾動。裏面一個movestart處理,手指的方向移動計算並防止該事件,如果發現它是向上,還是向下::

jQuery('.mydiv') 
 
.on('movestart', function(e) { 
 
    // If the movestart is heading off in an upwards or downwards 
 
    // direction, prevent it so that the browser scrolls normally. 
 
    if ((e.distX > e.distY && e.distX < -e.distY) || 
 
     (e.distX < e.distY && e.distX > -e.distY)) { 
 
    e.preventDefault(); 
 
    } 
 
});