How to recognize the vertical direction of a finger moving up or down on mobile devices when scrolling a page using javascript (Jquery)? Methods based on scroll events, unfortunately, do not work correctly when hiding and showing blocks. I need a touch based method. The code below works only partly for some reason at the second touch of the screen:
$(window).on('touchstart', function(e){ var touchobj = e.changedTouches[0]; // первая точка прикосновения starty = parseInt(touchobj.clientY); // положение точки касания по y, относительно левого края браузера e.preventDefault(); $(window).on('touchmove', function(event){ var touchobj = event.changedTouches[0]; // первая точка прикосновения для данного события var dist = parseInt(touchobj.clientY) - starty; if(dist>0){ jQuery('#btn_mobile').css('opacity', '1'); jQuery('#btn_mobile').css('z-index', '9999'); } else{ jQuery('#btn_mobile').css('opacity', '0'); jQuery('#btn_mobile').css('z-index', '0'); } e.preventDefault(); }, false); }, false);