5

私は<div>タグを持っていて、ユーザーがそれをスワイプするとログに記録されswipeます。スワイプは3つあります。つまりswipe、 jQuery Mobileにはswipeleftありますがswiperight、使用したいのは1つswipeだけです。私が知りたいのは、ユーザーがタグをスワイプしてから、ユーザーのスワイプ方向に基づいて<div>ログを記録するときです。出来ますか?はいの場合、どのように?swipeleftswiperight

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

1 に答える 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" );
    }
}
于 2013-02-28T09:07:46.273 に答える