簡體   English   中英

如何在iPad上滾動滾動工作jQuery?

[英]How to make work jquery “swipe” with scroll on iPad?

我有兩個div,彼此相鄰。 除了click事件外,我還添加了swiperightswipeleft的功能。 但是,當我添加這些swipe事件時,在iPad上滾動不再起作用。 在PC上沒有問題!

還有其他方法可以使它們在iPad(觸摸屏設備)上彼此兼容嗎?

謝謝!

找到一個解決方案:

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

滑動事件是基於移動事件(stephband.info/jquery.event.move)構建的精簡包裝。 默認情況下,移動事件會覆蓋本機滾動,因為它們假定您要移動某些內容而不是滾動窗口。 要重新啟用滾動,請在movestart處理程序中調用e.preventDefault()。

在上面的示例中,我們希望能夠向左和向右滑動,但可以上下滾動。 在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(); } }); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM