
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the role of clearTimeout() function in JavaScript?
If you have set a time using setTimeout() function, then you can clear it using the JavaScript clearTimeout() function.
Example
You can try to run the following code learn how to implement clearTimeout() function in JavaScript −
<html> <head> <title>JavaScript Animation</title> <script> <!-- var imgObj = null; var animate ; function init() { imgObj = document.getElementById('myImage'); imgObj.style.position= 'relative'; imgObj.style.left = '0px'; } function moveRight() { imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px'; animate = setTimeout(moveRight,20); // call moveRight in 20msec } function stop() { clearTimeout(animate); imgObj.style.left = '0px'; } window.onload =init; //--> </script> </head> <body> <form> <img id = "myImage" src = "/images/html.gif" /> <p>Click the buttons below to handle animation</p> <input type = "button" value = "Start" onclick = "moveRight();" /> <input type="button" value="Stop" onclick="stop();" /> </form> </body> </html>
- Related Questions & Answers
- What is the role of throw statement in JavaScript?
- What is the role of filter() method in JavaScript?
- What is the role of Navigator object in JavaScript?
- What is the role of pageXOffset property in JavaScript?
- What is the role of scrollY property in JavaScript?
- What is the role of scrollX property in JavaScript?
- What is the role of parseFloat() method in JavaScript?
- What is the role of parseInt() method in JavaScript?
- What is the role of the window.history object in JavaScript?
- What is the role of brackets ([ ]) in JavaScript Regular Expressions?
- What is the role of exec method in JavaScript RegExp?
- What is the role of global RegExp property in JavaScript?
- What is the role of source RegExp property in JavaScript?
- What is the role of lastIndex RegExp property in JavaScript?
- What is the role of altKey Mouse Event in JavaScript?
Advertisements