jQuery Mobile 滑动事件

Om3*_*3ga 5 jquery jquery-mobile

我有一个<div>标签,当用户在它上面滑动时它会记录swipe。有三种,即挥笔swipeswipeleftswiperight在jQuery Mobile的,但我想用swipe而已。我想知道的是,当用户滑过<div>标签然后记录swipeleftswiperight基于用户的滑动方向。是否可以?如果是,那么如何?

$('.image').on('swipe', function (e) {
    console.log('swipe);
});
Run Code Online (Sandbox Code Playgroud)

Cli*_*ard 4

要记录向左滑动,请使用

    $('.image').on('swipeleft', function (e) {
       console.log('swipeleft');
    }); 
Run Code Online (Sandbox Code Playgroud)

为权利

    $('.image').on('swiperight', function (e) {
       console.log('swiperight');
    });
Run Code Online (Sandbox Code Playgroud)

$(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" );
    }
}
Run Code Online (Sandbox Code Playgroud)