jQuery Mobile滑动事件 [英] jQuery Mobile swipe event

查看:101
本文介绍了jQuery Mobile滑动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有< div> 标记,当用户滑过它时,它会记录 swipe 。有三个滑动即滑动 swipeleft swiperight in jQuery Mobile但我只想使用 swipe 。我想知道的是,当用户滑过< div> 标记然后记录 swipeleft swiperight 根据用户的滑动方向。可能吗?如果是,那么如何?

I have a <div> tag and when user swipes over it then it logs swipe. There are three swipes i.e. swipe, swipeleft and swiperight in jQuery Mobile but I want to use swipe only. What I want to find out is when user swipe over <div> tag then log either swipeleft or swiperight based on user's swipe direction. Is it possible? If yes then how?

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


推荐答案

要记录向左滑动,请使用

To log a swipe left use

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

正确

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

将此项放入函数 $(document).on('pageinit' ,function(){} 你的代码。

place this in the function $(document).on('pageinit', function() {} of your code.

这些事件可以扩展,这是这些事件的默认值

These events can be extended, this is the default for these events

$。event.special.swipe.handleSwipe:

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

这篇关于jQuery Mobile滑动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆