2

当用户向下滚动其移动设备的页面时,我想禁用 touchstart 事件。该页面有各种元素,当您单击时会切换一个类,但我希望当用户向下滑动以向下滚动页面时禁用 touchstart 事件。

查询

$(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 回答