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;                                             
};

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
enable swipe using javascript how to add swipe functionality for phone on javascript swipe functionality javascript swiper js enabled how to implement swipe in javascript javascript detect swipes slide event in javascript javascript swipe right event swipe in javascript swipe from right to left event javascript right to left swipe event javascript swipe 2 var js run function after swipe swipable onswipe right pure js event finger slide css javascript eventlistener swipe swiper js product swiper swiper in js swiper.js enable swipe on webpage using javascript swiper js javascript swipe left event swiper how to handle touch event detect swipe left right javascript in touch event javascript swipe menu swipe js function if click on next swipe js function when item on view detect swipe mobile javascript detect swipe down js fingerswipe js how to register a swipe right on mobhile onswipe call function in javascript detect user swipe in js js touch slide event how to register a swipe right on mobhile css javascript swipe left and swipe right es6 swipe div event onswipe javascript on events swipe js document handle swipe css swip ios swipe up event listener js ios swipe up event listener js swipe up event listener ios js javascript swipe example add event listener swipe up javascript event listener swipe javascript swipe detect left or right handle swipe gesture javascript javascript element swipe js touch swipe detect swipe up javascript in website detect swipe up javascript enable javscript swipe left touch js swipe events js on swipe left swipe detect javascript javascript detect swipe swipe left right js swipe right javascript fire event only when swiping js detect if swipe right js create a swipe up in javscript detect swipe from edge css ecmascript swipe functions javascript swipe from left to right js swipe detect swipe in javascript on right swipe javascript recognize swipe in js how to detect swipe in js swipe event in javascript event swipe js how to add a swipe gesture in js how to swipe left or right on javascript detect swipe js position swipe element javascript js detect swipe javascript trigger swipe detect swipe and drag javascript how to listen for swipe up with javascript swipe detection javascript how to listen for swipe with javascript javascript swiping javascript mobile swipe event swipe detector javascript js swipe event how to detect if a div is swiped in js html5 event listener event listener for swipe in html js swipe detection css javascript event mobile swipe register swipe right javascript on swipe down swipe down event javascript html mobile input swipe event up down left right swipe detect mobile swipe js event swipe right detext js how to add swiping event listener in javascript check swipe on ios javascript check touch or swipe on ios javascript web swip direction javascript detect swipe left get swipe event on mobile javascript detect swipe direction javascript swipe event javascript js handle swipe events javascript on swipe function javascript on swip function html swipe right left gestujre js addevent listener finger slide js on swipe right javascript swipe event javascript on swipe javascript detect swipe left or right swipe in js event listener swipe swipe javascript how to listen for finger leaving screen javascript detect slide event js javascript swipe down event css listen to swipe down javascript listen to swipe down mouse swipe left and right javascript swipe left and right javascript detect swipe left right javascript how to make swipe event screen swipe js onswipe js javascript swipe detect swipe javascript detect swipes javascript handle swipe left and right javascript swipe right swipe left javascript swipe right event javascript javascript detect swipe on mobile ios javascript detect swipe on mobile swipe event listener
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source