2

ユーザーがモバイル デバイスのページを下にスクロールしたときに touchstart イベントを無効にしたいと考えています。ページにはさまざまな要素があり、クリックするとクラスが切り替わりますが、ユーザーが下にスワイプしてページを下にスクロールすると、タッチスタートイベントが無効になります。

Jクエリ

$(document).on('touchstart click', '.flip-container ', function(event){                       
         event.preventDefault();
        $(this).find('.flipper').toggleClass('hover');
}); 

誰でも方法を知っていますか?ありがとう!

4

3 に答える 3

7
var touchmoved;
$('button').on('touchend', function(e){
    if(touchmoved != true){
        // you're on button click action
    }
}).on('touchmove', function(e){
    touchmoved = true;
}).on('touchstart', function(){
    touchmoved = false;
});

https://stackoverflow.com/a/32120668/3678996

于 2015-08-20T14:10:31.803 に答える
1

ページがスクロールしているときにフラグを使用し、スクロールしていないときにのみそのクラスのトグルを追加できると思います。何かのようなもの:

//SET THE FLAG
var scrolling = false;
var endScrolling;

$(window).on("scroll", function() {
    scrolling = true;
    endScrolling = window.setTimeout(function() {
        scrolling = false;
        window.clearTimeout(endScrolling);
    }, 20);
});


$(document).on('touchstart click', '.flip-container ', function(event){                       
     event.preventDefault();
    //BLOCK THE CLASS TOGGLE IF THE PAGE IS SCROLLING
    if(!scrolling) {
        $(this).find('.flipper').toggleClass('hover');
    }
}); 
于 2013-12-16T16:38:16.503 に答える
0

次のようなことを試すことができます:

var initialValue;
var finalValue;

$( 'body' ).on( 'touchstart', 'yourSelectorHere', function() {
    initialValue = $( this ).offset().top;
}).on( 'touchend', 'yourSelectorHere', function() {
    finalValue = $( this ).offset().top;
});

$( 'body' ).on( 'touchend', 'yourSelectorHere', function(e) {
    setTimeout( function(){ // is time for get the finalValue
        if( initialValue == finalValue ){
            // your code here
        }
    }, 300);
});
于 2015-12-17T16:04:24.450 に答える