This is another demo from Paul Rouget. It’s a very simple demonstration of what you can do when you combine video, SVG and some fun transformations.
This puts a HTML5-based <video> element into an SVG document like so:
If you look at the rest of the source code you will also see that the rest of the player is also defined and controlled from SVG. And we’re also using some of the CSS and SVG capabilities that are in Firefox 3.5 to define the player as well. For example if you look at the CSS you will see:
#video {
filter: url(#filter);
clip-path: url(#circle);
}
The <a href="https://developer.mozilla.org/En/Applying_SVG_effects_to_HTML_content#Example.3a.c2.a0Clipping">clip-path</a>
property lets you define a clip path for any element – html, svg or otherwise. This can be extremely powerful and can be any arbitrary path defined in SVG. Much like a cookie cutter this cuts out the center of the otherwise square video and uses that for display. Here’s what our clip path looks like:
The <a href="https://developer.mozilla.org/En/Applying_SVG_effects_to_HTML_content#Example.3a.c2.a0Filtering">filter</a>
property lets you define an SVG filter to use in the same way as a clip path. In our case we use a feColorMatrix:
Although it is not used in this demo note that you can also use SVG to define gradient masks for any element in Firefox 3.5 as well.
When the video runs it uses the transformation property to rotate the video while it’s playing:
function rotateMePlease() {
// Sure
if (!video) return;
video.style.MozTransform='rotate(' + i + 'deg)';
i += 3;
}
You will notice that Paul built this into an XHTML document, carefully using namespaces and XML syntax. But most people would probably want to use SVG in plain-old-HTML. In Firefox 3.5 there is a way to do this using SVG External Document References. What this means is that instead of defining your SVG in the HTML file directly you can define it in its own file and refer to it through CSS like this:
.target { clip-path: url(resources.svg#c1); }
What this does is load the SVG from the resources.svg file and then use the object with the ID “c1” as the clip path for the target. This is a very easy way to add SVG to your document without making the full switch to XHTML.
I hope that this gives you a taste of what’s possible when mixing SVG, HTML, video and CSS all together. Enjoy!
About Christopher Blizzard
Making the web better, one release at a time.
20 comments