Detect scrolling after scrolling distance from current position in browser

后端 未结 3 1788
滥情空心
滥情空心 2021-01-22 13:21

I want to detect if i am scrolling but only after I\'ve scrolled a certain distance from my current location. When I stop scrolling, this distance resets to the current location

3条回答
  •  迷失自我
    2021-01-22 13:47

    with this i was able to get the swipe up and down...
    

    i add a flag so it only run once that fix the problem of keep swiping. thanks to https://css-tricks.com/forums/topic/detect-vertical-direction-of-jquery-touchmove/

    currentY:
    var swipe = false,
    var lastY,
    timer;
    $(document).bind('touchstart', function(e) {
    
    lastY = e.originalEvent.touches ? e.originalEvent.touches[0].pageY : e.pageY;
    console.log(lastY);
    });
    $(document).bind('touchmove mousemove', function(e) {
    
    var currentY = e.originalEvent.touches ? e.originalEvent.touches[0].pageY : e.pageY;
    
    if(!swipe){
    if (Math.abs(currentY-lastY) < 50) { return; }
     swipe = true;
    if (currentY > lastY) {
    console.log('down');
    } else {
    console.log('up');
    }
    }
    }).on('touchend', function(){
      swipe = false;
    });
    

提交回复
热议问题