HTML DOM touchstart इवेंट तब ट्रिगर होता है जब टच स्क्रीन को टच किया जाता है।
नोट: यह इवेंट केवल टच डिवाइसेज के लिए है।
सिंटैक्स
HTML में touchstart इवेंट ट्रिगर करना -
ontouchstart = "eventFunction()"
JavaScript में touchstart इवेंट ट्रिगर करना -
eventObject.ontouchstart = eventFunction
नोट: हमने टच इवेंट उदाहरणों को मोबाइल या टच एक्सेस वाले सिस्टम पर ऑनलाइन HTML एडिटर्स पर चलाया है।
उदाहरण
<!DOCTYPE html> <html> <head> <title>HTML DOM touchstart event</title> <style> form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 50%; font-size: 20px; padding: 20px; border: 5px solid rgb(220, 53, 69); background: rgba(220, 53, 69, 0.5); color: #fefefe; } </style> </head> <body> <form> <fieldset> <legend>HTML-DOM-touchstart-event</legend> <label for="textSelect">Game Time</label> <input type="button" id="gameSelect" value="Hold On"> <div id="divDisplay">Hold On for 1 - sec to Win</div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var gameSelect = document.getElementById("gameSelect"); var duration = 1000; var timer; gameSelect.ontouchstart = startEventAction; function startEventAction() { timer = setTimeout(victory, duration); } gameSelect.ontouchend = endEventAction; function endEventAction(){ if(timer) clearTimeout(timer); } function victory(){ divDisplay.textContent = "You Win" } </script> </body> </html>
आउटपुट
'Hold On' बटन को टच करने से पहले -

स्क्रीन पर 'Hold On' बटन को टच करने के बाद -
