जावास्क्रिप्ट में टच इवेंट्स तब फायर होते हैं जब कोई यूजर टचस्क्रीन डिवाइस के साथ इंटरैक्ट करता है।
निम्नलिखित पॉइंटर इवेंट प्रॉपर्टीज हैं:
| इवेंट | विवरण |
|---|---|
| touchstart | यह तब फायर होता है जब टच पॉइंट टच सरफेस पर रखा जाता है। |
| touchmove | यह तब फायर होता है जब टच पॉइंट टच सरफेस के साथ मूव करता है। |
| touchend | यह तब फायर होता है जब टच पॉइंट टच सरफेस से हटाया जाता है। |
| touchcancel | यह तब फायर होता है जब टच पॉइंट बाधित होता है। |
जावास्क्रिप्ट में टच इवेंट्स के लिए कोड निम्नलिखित है:
उदाहरण
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; color: blueviolet; font-weight: 500; } .sample { color: red; } </style> </head> <body> <h1>Touch events in JavaScript</h1> <div class="sample">Here is some sample text to touch</div> <div class="result"></div> <h3>Touch on the above paragraph to make output in the below paragraph visible</h3> <script> let resEle = document.querySelector(".result"); let sampleEle = document.querySelector(".sample"); sampleEle.addEventListener("touchstart", () => { resEle.innerHTML = "Touch start event has been triggered"; }); </script> </body> </html>
उपरोक्त कोड निम्नलिखित आउटपुट उत्पन्न करेगा:
आउटपुट

पैराग्राफ को टच करने पर:
