Our first test translated the fox across the screen using CSS animation. It was jerky in the iOS email client as mobile devices don’t have the processing power of a desktop computer. It wasn’t the file size which was pretty low, but how long it takes to redraw all that data each frame.
It needs to calculate all those positions each time, and then all the gradients to fill the shapes. Scalable vectors are generated on the fly which takes processing power, and unlike video or JPEG compression there’s no hardware assistance in rendering the SVG.
The fox artwork could have been more lightweight. The shape on the left will draw quicker than the more detailed shape on the right, as polygons = data = performance.
SVG animation vs. CSS animation
After that first test we switched to native SVG animation. We didn’t benchmark it, but just by eyeballing it SVG animation appeared to have the edge. While basic transformations are covered with either technique, they do have different capabilities. Also the way you’d code them with the CSS in the head has implications for email designers.
We didn’t base64 the demos below, so you can take a look at the source code. Though you can base64 SVG animation and send via email, just like we did for the static tests.
Ease in, ease out?
Without being able to ease in and out you’ll end up with really crude animation. Luckily we can do easing and faring with SVG animation, as you can see with Graeme’s bouncing ball.
SVG animation is time-based, you set the duration of the animation, e.g 10 seconds from start to finish. All keytimes are in the range of 0-1, so if you had 10 keyframes in our 10 sec animation you could set keyframe 1 at 0.1 sec, keyframe 2 at 0.3 and keyframe 3 at 0.4 ect.
You can also set keysplines, this allows you to control the animation more precisely. It sets the rate of change between key values, and is governed by keytimes allowing for easing and faring. Its a bit tricky as there’s no graphical representation of the spline, so you just guesstimate.
Animate polygon points?
If we can manipulate the points of a polygon we can create slick animations. Here we created an SVG with 10 points which morphs into various shapes, such as a star into a square. Each keyframe has to have the same number of vertices, in the same order. As it’s tweening we get a smooth transition, because its drawing all the in-between states. We are using keysplines here also, to control the motion so its not just linear.
It’s fairly efficient (5K), though you do have to specify the new point positions for each keyframe so it’s not without overhead. Unfortunately we could only get vertex animation to work under Firefox, which rules it out.
We can’t animate the points of a polygon, only the polygons themselves. So the type of animation we can create is what I think of as paperdoll animation, whereby each limb is on a hinge.
In order to get the fox tail to thump (every 16sec) we created two groups for the tail, back and front. We then set the anchor point for each group - like the silver pins on the mermaid - which you pivot around. The tail animation consists of a rotate and translate, with the back and front synced. There’s no IK skeleton, no ‘parent group’ so you just have to wing it.
To get the fox to blink (every 6sec), Graeme duplicated the eye polygons to make eyelids and then animated them. It’s a simple transformation in X and Y, again governed by keysplines to get the snap. The eyelid travels from behind the brow, along the edge of the nose. The face polygons had to be reordered to hide the eyelids behind the brow, but in front of the eye.
Graeme did some similar tweaking with the tail, as there were no hind leg or paws behind it just dead space. Obviously when planning this type of animation, you’d take overlapping into consideration. Here we just used artwork that was on-hand for testing, and it needed reworking.
Implementing something more complicated like a walk-cycle might be difficult without an interface of some sort. Though it’s very efficient as you are translating just one set of points (the tail is not changing shape just moving around).
Here it went from 18K when static, to just 22K with the blink, and 24K with both the blink and tail thump. As base64 code it rises to 31K, you might have to do this conversion to send via your ESP. SVG animation is supported under the iOS and Android email client (and looked nice and smooth btw). There’s a more detailed SVG email support chart here.
Isolated groups or whole SVGs
The most accessible type of SVG animation is whereby you transform a whole group that moves independently. Such as a balloon moving upwards or a spinning wheel. You can layer on translate, rotate, scale, show, hide, color changes to nice effect like on madebyfieldwork.
The ‘paperdoll’ technique has promise, its efficient and with the right artists you could create some lovely work. It’s a shame about vertex animation, but there’s one other avenue open to us which I’ll look at next.