Get started with touchjs CDN

MIT licensed

TouchJS is a library for handling touch events in web applications.

Tags:
  • baidu
  • clouda
  • touch
  • touch.js
  • gesture

Stable version

Copied!

How to start using touchjs CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with touchjs CDN - cdnhub.io</title>
  <script src="https://cdn.cdnhub.io/touchjs/0.2.14/touch.min.js"></script>
  <style>
    #touch-area { width: 100px; height: 100px; background-color: #ccc; }
  </style>
</head>
<body>
  <div id="touch-area"></div>
  <script>
    const touchArea = document.getElementById('touch-area');

    touchArea.addEventListener('touchstart', function(event) {
      event.preventDefault();
      console.log('Touch started');
      const touch = event.changedTouches[0];
      console.log('Touch position:', touch.pageX, touch.pageY);
    });

    touchArea.addEventListener('touchmove', function(event) {
      event.preventDefault();
      console.log('Touch moved');
      const touch = event.changedTouches[0];
      console.log('Touch position:', touch.pageX, touch.pageY);
    });

    touchArea.addEventListener('touchend', function(event) {
      event.preventDefault();
      console.log('Touch ended');
      const touch = event.changedTouches[0];
      console.log('Touch position:', touch.pageX, touch.pageY);
    });
  </script>
</body>
</html>
Copied!
Copied!

All versions