All examples By author By category About

cloudshapes

attrTween in a Transition to Move an Element Using a Function

Using attrTween in a Transition to Move an Element Using a Function

Kind of an evolution from Mike Bostock's ball-following-a-path example.

Mike Bostock's code uses attrTween and transform to move a ball in a transition along a pre-determined set of points. So Mike's code creates a route using a 'path' element, then uses the attrTween and transform to navigate along those sets of points.

This code uses attrTween and transform, but the code that actually does the moving uses a function to generate the points for the balls to move to.

The code also has the data specify which pattern the balls should follow: a circular or elliptical path?

Why do this? It opens up all kinds of possibilities to controlling and manipulating movement from within transitions. What's also quite cool is that you can still use all the various "ease parameters".