This project provides a hands-on demonstration of JavaScript touch events. It aims to help developers understand how to capture and handle touch interactions on web pages. The demo visually represents touch points and showcases features like multi-touch, pinch-to-zoom, and draggable elements.
This project is automatically deployed to GitHub Pages. You can access the live demo at: Live Demo
(Note: You might need to enable GitHub Pages in your repository settings and ensure the deployment URL is correct.)
This demo illustrates several touch event capabilities:
Basic Touch Event Handling (touchstart, touchmove, touchend, touchcancel):
touchstart: Creates a visual marker (a colored dot) at each touch point.touchmove: Updates the position of the visual marker to follow your finger.touchend: Removes the visual marker when you lift your finger.touchcancel: Removes the visual marker if the touch is interrupted (e.g., by a browser gesture).Multi-touch Visualization:
Pinch-to-Zoom Example:
Draggable Element:
event.preventDefault(). The element is also constrained to stay within the viewport.git clone https://github.com/Justinjdaniel/learn-TouchEvents.git
cd learn-TouchEvents
Open the demo in your browser:
Navigate to the public/ directory and open the index.html file in a web browser that supports touch events (most modern browsers do). For desktop development, browser developer tools often provide touch emulation.
[!Tip] If you have Python installed, you can run
python -m http.serverfrom the project root and then navigate tohttp://localhost:8000/public/in your browser. Node.js users can usenpx live-serverfrom the root.
This project uses ESLint for JavaScript linting and Prettier for code formatting to maintain code quality and consistency.
npm install
npm run lint
npm run lint:fix
npm run format