Skip to main content
100%

Transition Values with a Timer

✓ Published0🌍 Public
Aandrew-reid
Last edited Jul 15, 2017
Created on Jul 15, 2017

A circle transitions from the upper-left to the lower-right of an SVG canvas over five seconds, while a text label beside it continuously updates to display the circle's current x-coordinate. The code uses d3.transition to animate the circle's attributes and a d3.timer to poll the circle's rendered cx value during the animation, stopping after 5,000 milliseconds. This demonstrates an alternative to transition.attrTween for reading interpolated values, relying on timer-driven attribute inspection rather than tween callbacks.

AI-generated description

This method of getting interpolated attribute values during a transition uses a timer ( as opposed to a tween function ) which can be started at the beginning of a transition and repeatedly finds the value of a given element's attribute until stopped (this could be stopped by a transition end event itself). The other option using a timer is to use the timer itself to transition an object. This approach can be found in this answer on SO.

Similar vizzes