jQuery Mobile滑动事件

5
我有一个 <div> 标签,当用户在其上滑动时,它会记录swipe。jQuery Mobile 中有三种滑动方式,即swipeswipeleftswiperight,但我只想使用 swipe。 我想找出的是,当用户在 <div> 标签上滑动时,根据用户的滑动方向记录swipeleftswiperight。是否可能?如果是,则如何实现?
$('.image').on('swipe', function (e) {
    console.log('swipe);
});
1个回答

4
记录向左滑动使用以下代码:
    $('.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" );
    }
}

这有帮助吗?你想扩展默认事件吗? - Clinton Ward
你能举个例子展示如何扩展handleswipe事件并获取方向,而不使用 swipeleftswiperight 吗? - But those new buttons though..

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接