Timer API module is used to perform the concurrent animations with synchronized timing delay. It uses requestAnimationFrame for animation. This chapter explains Timer API module in detail.
This method tells the browser that you wish to perform an animation and requests that the browser call a specified function to update an animation.
We can easily load the timer directly from d3js.org by using the following script.
<script src = "https://d3js.org/d3-timer.v1.min.js"></script> <script> var timer = d3.timer(callback); </script>
The Timer API supports the following important methods. All of these are explained in detail as follows.
This method returns the current time.
This method is used to schedule a new timer and invokes the timer until stopped. You can set a numeric delay in MS, but it is optional otherwise, it defaults to zero. If time is not specified, it is considered as d3.now().
Restart a timer with the specified callback and optional delay and time.
This method stops the timer, preventing subsequent callbacks.
It is used to stop the timer on its first callback. Callback is passed as the elapsed time.
It is invoked on a particular time delay interval. If delay is not specified, it takes the timer time.
Create a webpage “timer.html” and add the following script to it.
We will see the following response on the screen.