Javascript DOM touchmove Event

Introduction

Execute a JavaScript when the user moves the finger over a P element.

This example is for touch devices only.

View in separate window

<!DOCTYPE html>
<html>
<body>

<p ontouchmove="myFunction(event)">
Touch this paragraph, and move the finger to trigger a function that will display the x and y coordinates of the touch, according the the document:</p>
<p id="demo"></p>

<script>
function myFunction(event) {/*from  w w  w .ja  va  2 s  . com*/
  var x = event.touches[0].clientX;
  var y = event.touches[0].clientY;
  document.getElementById("demo").innerHTML = x + ", " + y;
}
</script>

</body>
</html>

The touchmove event occurs when the user moves the finger across the screen.

The touchmove event will be triggered once for each movement, and will continue to be triggered until the finger is released.

Bubbles: Yes
Cancelable: Yes
Event type: TouchEvent
Supported HTML tags: All HTML elements



PreviousNext

Related