Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect touch scroll up or down

I need code same this for touch devices . help me please

$(window).on('DOMMouseScroll mousewheel', function (e) {
    if (ScrollEnable) {
        if (e.originalEvent.detail > 0 || e.originalEvent.wheelDelta < 0) {
            console.log('Down');
        } else {
            console.log('Up');
        }
    }
    return false;
});

and here is my touch code, But consul just take up i need find down for my website ! what can i do :|

$('body').on({
    'touchmove': function(e) {
        if (e.originalEvent.touches > 0 || e.originalEvent.touches > 0) {
            console.log('Down');
        } else {
            console.log('Up');
        }
    }
});
like image 223
Morteza Negahi Avatar asked Sep 15 '26 00:09

Morteza Negahi


2 Answers

var updated=0,st;
$('body').on({
    'touchmove': function(e) { 
    st = $(this).scrollTop();
    if(st > updated) {
        console.log('down');
    }
    else {
        console.log('up');
    }
    updated = st;
    }
});
like image 61
Salka Moses Debbarma Avatar answered Sep 16 '26 14:09

Salka Moses Debbarma


You can use scroll event

var lastScrollTop = 0;
$(window).scroll(function(event){
var st = $(this).scrollTop();
if (st > lastScrollTop){
   // downscroll code
} else {
  // upscroll code
}
lastScrollTop = st;
});
like image 41
Owais Aslam Avatar answered Sep 16 '26 14:09

Owais Aslam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!