jQuery Mobile滑动事件
我有一个
标签,当用户滑过它时,它会记录
swipe
。 在jQuery Mobile中有三种滑动,即swipe
, swipeleft
和swiperight
,但我只想使用swipe
。 我想知道的是当用户滑过
标签然后根据用户的滑动方向记录swipeleft
或swiperight
。 可能吗? 如果是,那怎么样?
$('.image').on('swipe', function (e) { console.log('swipe); });
要记录向左滑动使用
$('.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" ); } }