【问题标题】:jQuery Mobile swipe eventjQuery Mobile 滑动事件
【发布时间】:2013-02-14 09:21:57
【问题描述】:

我有一个<div> 标签,当用户在它上面滑动时,它会记录swipe。在 jQuery Mobile 中有三个滑动,即 swipeswipeleftswiperight,但我只想使用 swipe。我想知道的是,当用户在<div> 标签上滑动,然后根据用户的滑动方向记录swipeleftswiperight。可能吗?如果是那怎么办?

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

【问题讨论】:

    标签: jquery jquery-mobile


    【解决方案1】:

    要记录向左滑动使用

        $('.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" );
        }
    }
    

    【讨论】:

    • 这有帮助吗?您是否希望扩展默认事件?
    • 你能举例说明如何在不使用swipeleftswiperight的情况下扩展handleswipe事件并获取方向吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-07
    • 2015-09-25
    • 1970-01-01
    • 1970-01-01
    • 2012-04-03
    • 1970-01-01
    相关资源
    最近更新 更多