📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials jQuery in Practice Touch Events

Touch Events

5 min read
Handle touch with touchstart and touchend. Read coordinates from e.originalEvent.touches[0]. Detect swipes by comparing start and end X positions. Use Hammer.js for complex gestures like pinch and rotate.

Touch Events

$('#slider').on('touchstart', function(e) {
  const touch = e.originalEvent.touches[0];
  startX = touch.clientX;
});
$('#slider').on('touchend', function(e) {
  const touch = e.originalEvent.changedTouches[0];
  const diff = touch.clientX - startX;
  if (diff < -50) nextSlide();
  else if (diff > 50) prevSlide();
});