The timer.stop() function in D3.js is used to stop the current ongoing timer function thus preventing further calls to the function. This function will only work if the timer has not stopped yet.
Syntax:
timer.stop()
Parameters: It takes no parameters.
Returns: It doe not return anything.
Note: The Output should be different when run different times with the same code.
Below given are a few examples of the above function.
Example 1: When the timer is stopped and timer.stop() is used after that.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> </head> <style></style> <body> <!--Fetching from CDN of D3.js--> <script type="text/javascript" </script> <script> let func = function (e) { console.log( 'console.log("Timer stopped") will not be executed'); if (e > 300) { console.log("Timer stopped"); // This will have no effect as timer is stopped already timer.stop(); } // Timer stopped timer.stop(); }; // Delay of 2000ms var timer = d3.timer(func); </script> </body> </html> |
Output:
Example 2:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <style> .originalColor{ height: 100px; width: 100px; } .darkerColor{ height: 100px; width: 100px; } </style> <body> <!-- Fetching from CDN of D3.js --> <script type = "text/javascript" </script> <script> let func=function(e) { // Printing time elapsed console.log(e) if (e>=400){ console.log("Timer stopped.") // Timer stopped timer.stop(); } } // No delay given var timer = d3.timer(func); </script> </body> </html> |
Output:
Recommended Posts:
- How to get the function name from within that function using JavaScript ?
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to Check a Function is a Generator Function or not using JavaScript ?
- PHP | imagecreatetruecolor() Function
- p5.js | year() function
- D3.js | d3.utcTuesdays() Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- D3.js | d3.map.set() Function
- D3.js easePolyOut Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- D3.js | d3.bisectLeft() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


