enable swipe using javascript
document.addEventListener('touchstart', handleTouchStart, false);
document.addEventListener('touchmove', handleTouchMove, false);
var xDown = null;
var yDown = null;
function getTouches(evt) {
return evt.touches || // browser API
evt.originalEvent.touches; // jQuery
}
function handleTouchStart(evt) {
const firstTouch = getTouches(evt)[0];
xDown = firstTouch.clientX;
yDown = firstTouch.clientY;
};
function handleTouchMove(evt) {
if ( ! xDown || ! yDown ) {
return;
}
var xUp = evt.touches[0].clientX;
var yUp = evt.touches[0].clientY;
var xDiff = xDown - xUp;
var yDiff = yDown - yUp;
if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/
if ( xDiff > 0 ) {
/* left swipe */
} else {
/* right swipe */
}
} else {
if ( yDiff > 0 ) {
/* up swipe */
} else {
/* down swipe */
}
}
/* reset values */
xDown = null;
yDown = null;
};
Also in JavaScript:
- get recursion exponent power in javascript
- javascript array to comma separated list
- how to make sticky footer with react router
- putting a loop into an array javascript
- select elements id like jquery
- js is variable int
- send event to child component angular
- node js require file in parent directory
- javascript sort multidimensional array
- require a json as a string
- js array .filter
- js object destructuring with defaults
- angular serve
- Ocultar o mostrar elementos HTML con JQuery
- less than equal to in javascript
- cypress
- curl node exporter
- checkbox is checked jquery
- javascript last item in array
- javascript select element with two classes
- javascript is variable undefined
- how to flatten array with reduce in javascript
- react native text wrap
- javascript function with array parameter