// Register touch event handlers
someElement.addEventListener("touchstart", processTouchStart);
someElement.addEventListener("touchmove", processTouchMove);
someElement.addEventListener("touchcancel", processTouchCancel);
someElement.addEventListener("touchend", processTouchEnd);Using Touch Events / notebook
Using Touch Events
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
// touchstart handler
function processTouchStart(event) {
// Use the event's data to call out to the appropriate gesture handlers
switch (event.touches.length) {
case 1:
handleOneTouch(event);
break;
case 2:
handleTwoTouches(event);
break;
case 3:
handleThreeTouches(event);
break;
default:
gestureNotSupported(event);
break;
}
}// Create touchstart handler
someElement.addEventListener("touchstart", (event) => {
// Iterate through the touch points that were activated
// for this element and process each event 'target'
for (const touch of event.targetTouches) {
processTarget(touch.target);
}
});// touchmove handler
function processTouchMove(event) {
// Set call preventDefault()
event.preventDefault();
}