123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- ?>
- <script>
- window.onSwipe = function (el, callbackLeft, callbackRight ) {
- el.addEventListener('touchstart', handleTouchStart, false);
- el.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 ) {
- /* right swipe */
- callbackRight();
- } else {
- /* left swipe */
- callbackLeft();
- }
- } else {
- if ( yDiff > 0 ) {
- /* down swipe */
- } else {
- /* up swipe */
- }
- }
- /* reset values */
- xDown = null;
- yDown = null;
- };
- }
- </script>
|