HTML DOM touchmove Event

HTMLWeb DevelopmentFront End Technology

The HTML DOM touchmove event is triggered when touch is moved across the touch screen.

NOTE − This event is only for touch devices.

Following is the syntax −

Trigger touchmove event in HTML −

ontouchmove = "eventFunction()"

Trigger touchmove event in JavaScript −

eventObject.ontouchmove = eventFunction

Note − We ran Touch event examples on Online HTML Editors accessed on Mobile or systems with touch access. This is done so that we can perform touch operations like touch the screen for 2 seconds.

Let us see an example of touchmove event property −


 Live Demo

<!DOCTYPE html>
<title>HTML DOM touchmove event</title>
   * {
      padding: 2px;
   form {
      margin: 0 auto;
      text-align: center;
   #outer {
      margin: 0 auto;
      padding: 0;
      text-align: center;
      border:1px solid black;
      height: 105px;
      background-color: #28a745;
   input[type="button"] {
      border-radius: 10px;
   #upper {
      border-bottom: 1px solid black;
      height: 40px;
      margin: 0 0 15px 0;
      background-color: #DC3545;
   #lower {
      border-top: 1px solid black;
      height: 40px;
      margin: 15px 0 0 0;
      background-color: #DC3545;
         <legend>HTML DOM touchmove event</legend>
         <div id="outer">
         <div id="upper"><h2>Danger</h2></div>
         <div id="lower"><h2>Danger</h2></div>
         <input type="button" id="start" value="Start" onclick="gameStart()">
         <div id="divDisplay"></div>
   var divDisplay = document.getElementById('divDisplay');
   var gameDisplay = document.getElementById('outer');
   function playGame(event) {
      var x = event.touches[0].clientX;
      var y = event.touches[0].clientY;
         if(y > 95 && y < 110){
            divDisplay.textContent = 'Keep Going!';
               if(x === 439){
                  divDisplay.textContent = 'Congrats! You Did it!';
                  gameDisplay.removeEventListener('touchmove', playGame);
            divDisplay.textContent = 'You moved to DANGER area. You loose!';
            gameDisplay.removeEventListener('touchmove', playGame);
   function gameStart(){


After clicking ‘Start’ button and cursor in green (safe) area −

After clicking ‘Start’ button and cursor at end of green (safe) area −

After clicking ‘Start’ button and cursor in red (danger) area −

Updated on 08-Jul-2020 05:18:48