Reproducing A Clever Animation Product, Part 14

Today I shortened up the way transforms are specified. Rather than specify the type of transform and its explicit starting and ending values I combined the information using object literals. Here are the new specifications, each listed after the old way, which are commented out.

The starting value in this method is determined by the current value of the relevant property for each element. Getting the starting value can be straightforward in some cases and more complex in others. You can obtain the left edge location of an element by looking at element.style.left. However, the return value for element.style.transform will be more complex. The code I’ve written so far works only for the scale property and only if that is the only property specified. If multiple transforms are to be applied to an element they all have to be specified on the same line, otherwise only the last transform specified will have any effect. I’ll work on improving that tomorrow.

The ending value is determined directly from the supplied parameter in some cases (display and scale, for now), but indirectly for the left, top, and opacity properties (again, for now). In the latter cases the specified parameter is treated as an increment rather than a target value. This is admittedly a bit quirky and I’m going to have to think about it some.

If several transformations are defined that modify the same property over time the starting value for transitions after the first one is based on the ending value of the previous transition in time. It is assumed that the user has specified subsequent transitions that don’t start until the previous ones have finished, so I haven’t taken much effort to prevent someone from specifying something that might not work as expected.

Even more interestingly, multiple transforms can be combined into a single object literal as follows, though of course they will occur over the same time span.

The animation should look exactly the same as it has previously, so that means that I haven’t broken anything obvious. I’ll go into more details about the parts of the code I changed tomorrow.

This entry was posted in Tools and methods and tagged , , , . Bookmark the permalink.

Leave a Reply