Continuous ontouchmove?

423 Views Asked by At

How do I make this work on my Android mobile continuously, similarly to the way it works on my PC? Currently it doesn't:

<!DOCTYPE html>
<html>
  <head>
    <script>
(function() {
  document.onmousemove = handleMove; // for PC
  document.ontouchmove = handleMove; // for Mobile
  function handleMove(event) {
    document.getElementById('myDiv').innerHTML = event.pageX + "/" + event.pageY;
  }
})();
    </script>
  </head>
  <body>
    <div id="myDiv"></div>
  </body>
</html>
1

There are 1 best solutions below

0
On BEST ANSWER

On pc theres MouseEvent and on mobile TouchEvent. Create a separate function to handle mobile events.

function handleMobile(event) {
 document.getElementById('myDiv').innerHTML = event.touches[0].pageX + "/" + event.touches[0].pageY;
}