This article is the first in a series on various aspects of SVG.
Note: this isn't an overly technical article and is more of a detailed introduction into the power of SVG and it's animation capabilities than anything else.
To get started with SVG, you'll first need to download this from Adobe.
The easiest way to think of SVG is as a text (XML) - based Flash, but there's a lot more to it than that. SVG has been a W3C specification since September 4 2001 and it has started to get a lot of backing from the industry (viz: Corel, Adobe, Microsoft and well as a bunch of OSD applications) lately.
Currently, you'll need a plugin for your browser to view SVG files. When MS IE will natively support this standard is anyone's guess...
There are a couple of ways to package SVG files, with the primary ways being as a standalone file or embedded inside an HTML file using the <EMBED> tag. With SVG you can draw primitive shapes like circles, rectanges and lines as well as create complex animations based on time or triggered by events.
So, what elements are we going to be using in this article and what do they look like?
The "1" and "2" type attributes are the start and end points.
Mapping out the animation:
Instead of doing some boring animation to show what SVG can do, we'll construct a fairly detailed interactive demo for Code Project.
With this in mind, let's review some of the ways that animation can work within SVG.
How animation works:
Here's a quick demo to get this section started.
Given the rectangle example, this SVG will initially render a small rectangle that will get larger and larger.
If you have a look through the code, you'll see how simple it really is.
The main thing to note is that the animation is declarative. It can take quite a lot of getting used to, but by nesting an <animate/> element inside a shape element you can start to create more and more complex animations without writing any code.
The last point here, is that the animations are accumulative. Further on, we'll see some examples of this.
As I said earlier on, animations can be started based on two things: time and events. Here are some of the main events that you'll come across most often:
begin (an important event of animation elements)
load (actual rendering of the element)
While the first four should be immediately obvious to most programmers, the last two probably require a brief explanation...
"begin" signifies that an animation has started. This can be useful when you need to string together various animations as only one animation needs to fire the "begin" event and the rest can be listening for that. A chain reaction of soughts.
Here's what I mean:
"load" signifies that an element has been rendered onto the canvas. What actually seems to happen here, is the event fires when the element has been loaded into a memory-resident buffer and not necessarily when the actual paint has occured. If you test this by showing an alert box for this event, you'll see that the element has not yet appeared. Perhaps something to watch out for?
The two primary entities that can raise these begin and load events are: the various shape and animation elements respectively. With the animate elements typically being child elements of shapes.
We can modify the previous animation example to start based on a mouse over event, like this:
I've included a new attribute of the rectangle shape called "restart". All this does is stop the animation from restarting is if it still busy with the initial animation. Try and remove this and you'll see the animation go into a loop as the mouse over continually fires.
One of the massively useful features of SVG's animation events is that you can start an animation based on more than one event firing. For instance, we could have changed the begin attributes of the animation elements to:
Now, the "begin" attribute of this rectangle is listening for two events. I've changed the mouseover to a mouseout to better differentiate between the two examples.
You'll see a number of these more advanced software engineering features within the SVG spec.
To wrap up this intro article, here's an SVG file that demos some of the animation capabilities of SVG.