1

モバイルアプリにスワイプ効果を使用しようとしています。私はテストし、ページを変更するために動作します。しかし、その非常に敏感です。多くの場合、スクロールしたいだけで、彼はページを変更します。

このイベントでタッチスクリーンの感度を修正することは可能ですか?

ここに私のコードがあります:

$(document).on('swipeleft', '[data-role="page"]', function(event){    
    if(event.handled !== true) // This will prevent event triggering more then once
    {    
        var nextpage = $(this).next('[data-role="page"]');
        // swipe using id of next page if exists
        if (nextpage.length > 0) {
            $.mobile.changePage(nextpage, {transition: "slide", reverse: false}, true, true);
        }
        event.handled = true;
    }
    return false;         
});

$(document).on('swiperight', '[data-role="page"]', function(event){   
    if(event.handled !== true) // This will prevent event triggering more then once
    {      
        var prevpage = $(this).prev('[data-role="page"]');
        if (prevpage.length > 0) {
            $.mobile.changePage(prevpage, {transition: "slide", reverse: true}, true, true);
        }
        event.handled = true;
    }
    return false;            
});
4

2 に答える 2

5

horizontalDistanceThresholdjQuery Mobile では、水平方向と垂直方向のドラッグ距離とに新しい値を設定する必要がありますverticalDistanceThreshold

mobileinit変更をイベントにバインドする必要があり、 <head>jQuery js ファイルをロードした後、jQuery-Mobile js をロードする前にコードを配置する必要があることに注意してください。

<script src="jquery.js"></script>

<script>
$(document).bind("mobileinit", function(){
 $.event.special.swipe.horizontalDistanceThreshold = '100'; // default 30px
 $.event.special.swipe.verticalDistanceThreshold = '150'; // default 75px
});
</script>

<script src="jquery-mobile.js"></script>

参考:スワイプイベント - jQuery Mobile

于 2013-05-13T13:41:16.973 に答える
2

このようにスワイプのしきい値を調整します

$.swipe.defaults.threshold.x = '30'; //for horizontal swiping sensitivity
$.swipe.defaults.threshold.y = '10'; //for vertical swiping sensitivity

これらのコードを追加して、アプリケーションのスワイプのグローバル感度を変更し、上記のコードを配置した後に通常のコードを実行します

特定の要素の感度を直接変更するには、次のようなことができます

$('[data-role="page"]').swipe({ threshold: {x: 30, y: 20},
swipeLeft: function() { alert('swiped left') },
swipeRight: function() { alert('swiped right') }});
于 2013-05-03T17:38:02.077 に答える