2013-02-28 92 views
4

我有一個<div>標記,當用戶滑過它時,它會記錄swipe。在jQuery Mobile中有三個滑動即swipe,swipeleftswiperight,但我只想使用swipe。我想知道的是當用戶滑過<div>標籤,然後根據用戶的滑動方向記錄swipeleftswiperight。可能嗎?如果是,那麼如何?jQuery Mobile滑動事件

$('.image').on('swipe', function (e) { 
    console.log('swipe); 
}); 

回答

2

要登錄一個向左滑動,即可使用

$('.image').on('swipeleft', function (e) { 
     console.log('swipeleft'); 
    }); 

$('.image').on('swiperight', function (e) { 
     console.log('swiperight'); 
    }); 

這個地方在你的代碼的功能$(document).on('pageinit', function() {}

這些事件可以延長,這是對這些事件

$ .event.special.swipe.handleSwipe默認:

function(start, stop) { 
    if (stop.time - start.time < $.event.special.swipe.durationThreshold && 
     Math.abs(start.coords[ 0 ] - stop.coords[ 0 ]) > $.event.special.swipe.horizontalDistanceThreshold && 
     Math.abs(start.coords[ 1 ] - stop.coords[ 1 ]) < $.event.special.swipe.verticalDistanceThreshold) { 

     start.origin.trigger("swipe") 
      .trigger(start.coords[0] > stop.coords[ 0 ] ? "swipeleft" : "swiperight"); 
    } 
} 
+0

如何將這樣做是否有助於解決我的問題? – 2619 2013-02-28 09:10:44

+0

對不起,剛更新了答案 – 2013-02-28 09:16:15

+0

這有幫助嗎?你是否希望擴展默認事件? – 2013-02-28 10:34:07