There are about a hundred ways to add animation and interactivity to a webpage nowadays, including, but probably not limited to the following list of options that I’ve explored:
- CSS Transitions
- CSS Transforms (2D and 3D) + Javascript
- Flash
- JQuery/Javascript/JS Library Animation
- Webkit Keyframe Animations
- SVG Animation with Javascript
- SVG Animation with SMIL
- Canvas animation with javascript (2d context)
- WebGL in Canvas (3d context) animated with Javascript
Some of these are new, others have been around for a while. But with all these options, web developers should have no problem getting in bed with whichever technology is easiest for them to work with, and it’s off to the races, right? If it were only that simple. In fact, every option above has at least a few ‘gotchas’ that will keep you on your toes.
Let’s take a closer look at a few of these and look at some of the advantages, as well as their inevitable pitfalls.
Let’s start with Flash
I love flash. Why? Flash is an excellent platform for advanced animation and interactivity that runs very consistently on everything that supports it. If you develop something in Flash, you can generally expect it to look and operate the same on a PC as it will on a tablet or any other device, give or take performance ability based on processor power and a few other factors. Interfaces in Flash are highly customizable and there are numerous IDE’s out there for building and developing them. This all, incidentally, also means faster development time. And, Flash has been around a long time, and as such, it has been refined to the point where it is one of your most efficient options, performance-wise.
Flash player, being a plugin, can also theoretically be installed on just about any modern device (and for the most part, it can be), it would be natural to assume that it is your most compatible option.
In walks iOS. Alas, we all know that, being 2011, this is about a big a pitfall as a technology could face. We all want wickedly cool websites, but if it cannot work on a mobile device, what good is it? I realize iOS isn’t the only mobile OS out there, but it’s safe to say that a huge number of people love Apple shit. And that’s enough to turn one away, in some aspects.
Today, web/interactive developers have to decide, based on target audience, whether it’s worth it to build a potentially more advanced interactive website in a shorter timeframe, or instead adopt newer un-finalized technologies in an effort to achieve the same effect. This, of course, is if we want our product to be the same across different platforms and devices. In many cases, it may actually be easier to build different experiences for the various different devices which we’re targeting.
Summary: Flash is the winning interactive web and animation technology for PC’s, but not the right choice for a mobile audience- a growing market.
WebGL
WebGL is an open-source technology supported by a few newer browsers. It allows developers to make use of 3D Graphics API’s to build and incorporate some pretty impressive interactions into a webpage through the HTML5 canvas tag, without the need for any plugins. Some of the early experiments with WebGL are pretty impressive, and there are even some Javascript libraries like J3D popping up that will start to put some real power in the hands of developers looking to develop with it.
Unfortunately WebGL is still in it’s infancy, and is currently not even supported by iOS either. Because of the current lack of support, WebGL is probably still not ready for the masses, but will be interesting to keep an eye on this one as it develops.
Summary: Promising 3D graphics rendering technology that could be great for producing games on the web in the future, as well as numerous other potential applications.
SVG Animation
Surprisingly, there has not been as much hype about SVG animation as their has been about some of the other “HTML5″ technologies. SVG is another open source web technology, but for handling mainly vector graphics. I previously thought that you needed the <canvas> tag to work with SVG and vectors on the web, however this is not the case at all. I got particularly excited when I realized you can animate, manipulate and add interactivity directly to SVG graphics on a web page with some simple Javascript. This is all great news, since it is extremely easy to export graphics from a program like Adobe Illustrator.
Another way of animating SVG graphics is using SMIL. Which is basically another type of XML markup that can be used to configure some very simple animations within an SVG file. I haven’t experimented with SMIL extensively but looks like it could be useful in some cases for simple animations.
SVG animation is progressing quickly and is consistently getting growing browser support. There is even a library, SVGWeb, for adding backwards-compatibility for SVG to older browsers than did not support it. Unfortunately, SVG is currently not a robust enough specification to allow for animation and interactivity as advanced as something like Flash (which, as far as I’m concernced, is still the benchmark). And backwards-compatibility is spotty (even with a library like SVGWeb). It should also be noted that SVG is not primarily designed as an interactive vector format.
Summary: SVG is another promising technology. The concept of being about export vector graphics from Illustrator and simply assign animation and interactivity using Javascript is exciting. But there is still work to be done before it’s ready for prime-time.
CSS Transitions
CSS transitions recently captured my heart a little bit, at least as far as simple animations that do not require any kind of timeline are concerned. They are exactly that. They are useful for animating in between properties/style changes that occur on an HTML element. The nice thing about CSS transitions is that they are hardware accelerated, making them crazy smooth and sexy looking. Sorry, I got a little excited there.
Many people argue that CSS is not the place to be handling animations. And it’s a valid argument. But the deed has been done, and there are some obvious advantages – so it would be good now to at least see some improvements. For example, there is currently no way of tracking, or synchronizing, or modifying/stopping transitions as they run. The other issue of course is that CSS transitions are not supported by older browsers – namely the Windows OS default Internet Explorer versions <10.
Summary: CSS Transitions are very useful for enhancing the experience in newer browsers with some simple, easy-to-implement animations. However cannot be fully relied upon for a complete, consistent interactive experience for all users.
Webkit Keyframe Animations
Another option to throw on the pile is webkit keyframe animations. This is another method of configuring animation through CSS. As such, it uses a different syntax and approach than transitions. The advantage here though is that you can perform a more complex timeline of animations with the ability to track them a little better. And like CSS transitions, they are hardware accelerated too.
It seems to me that the people at webkit just weren’t getting what they wanted out of CSS transitions, so they just went ahead and built their own specification to do what they wanted. Which is fine. But at this point there are so many ways to animate things, that having yet another specification just adds to the confusion. It should also be mentioned that webkit browsers are currently the ONLY browsers to support this functionality.
Summary: Webkit keyframe animations are an interesting proposal to offer some necessary functionality for animation, but lack of support makes it difficult to get behind in the greater picture. They may, however, be quite useful in building mobile websites/applications since they would run fine in iOS or Android browsers.
Animation & Interactivity in HTML5 Canvas
There is a surprising amount of hype/fan following behind the HTML5 canvas. Granted, there are a number of pretty cool and even useful things that can be done with this technology. However, I think there is an even greater confusion as to what canvas actually is and does. Canvas is particularly great at drawing and manipulating graphics and rendering them – even in real time. Canvas supports drawing with either vector or raster graphics, though, the actual output is only raster.
Where canvas lacks, and what I think a lot of people don’t realize, is that canvas is really not a suitable medium for animation or interactivity as it stands. In fact, it is quite the opposite. Because there is no API for animation, developers wanting to simulate animation on the canvas need to clear and redraw the entire canvas at every frame. This can be extremely taxing and processor intensive. Furthermore, there are no actual nodes, or ways of accessing objects drawn onto the canvas using javascript. This means that in order to add interactivity to the actual canvas, a developer needs to specify, in a seperate manner, coordinates of the canvas that are to be interactive. Another inefficient method, both in terms of computing power and development time.
What I think canvas is most useful for is in it’s name – a canvas. There are a number of useful things it can do with graphics, and it certainly has its place in the HTML specification. Animation and interactivity, however, is not it.
Summary: Probably not actually a very practical choice for animation unless you’re making some sort of computer generated visualization. There are a number of other ways to animate, as noted above in this post, including SVG, that will in most cases have better performance and require less development time.