Warning: include(/home/45373/domains/dev.bowdenweb.com/html/constants.php) [function.include]: failed to open stream: No such file or directory in /nfs/c01/h06/mnt/45373/domains/dev.bowdenweb.com/html/css/ex/tta/index.php on line 2

Warning: include() [function.include]: Failed opening '/home/45373/domains/dev.bowdenweb.com/html/constants.php' for inclusion (include_path='.:/usr/local/php-5.3.29/share/pear') in /nfs/c01/h06/mnt/45373/domains/dev.bowdenweb.com/html/css/ex/tta/index.php on line 2

Using CSS3 Transitions, Transforms and Animation

New! Find the new blog at CSS/HTML news, techniques and information!

Intro

First things first - these demos are showing of CSS transitions, transforms (2D and 3D) and animations. Currently (January 2012), 2D transforms are available in all current browsers including IE9, transitions are available in all browsers except Internet Explorer 9 and less, while 3D transforms are in Safari, Chrome, Firefox and IE10 and up. Animations are available in Safari, Chrome, Firefox 5+ and IE10. Most examples degrade nicely, so if you are using a legacy browser you can still use a site using these, you just won't get animation. 3D transforms generally don't degrade nicely, so be careful when using them.

For a quick table summarising this, check out the supported browsers page.

None of the actual animation uses javascript, though I am using jQuery to add and remove classes to add interactivity. You can use the :target pseudo selector to do this in some cases, but I'm keeping it simple and extensible here.

If you are using iOS, replace hover with touch and hold wherever appropriate. (Check the script in the head if you are wondering how to replicate that effect.)

For most transitions I've just used two images to keep the examples simple. Most should be easy to extend to different content (videos, text, etc) or more than two images, though you may need to add and remove appropriate classes with JS in order to get the desired effect.

Of particular note is that animations that don't require a repaint (transforms and opacity) are hardware accelerated on Webkit, so if you are building a mobile site you definitely should be using this rather than things like the jQuery animate method.

To see a demo showing exactly how much faster transitions are than the older methods of doing things, check the speed comparison.

To make it easier to view source and copy, I'm putting style and script tags in each section, just before the demo. This isn't recommended for production use, but in this instance it will hopefully help.

Any suggestions/improvements/etc, contact me via my gmail account (rich.bradshaw), or on Twitter (richbradshaw).

Keep reading to see the main explanations, or for some more experimental demos with less explanation, check out the demos page.

Will it work for me?

Green means yes, red means no.

CSS Transitions

CSS 2D Transforms

CSS 3D Transforms

CSS Animations

Contents


Warning: include(/home/45373/domains/dev.bowdenweb.com/html/contents.php) [function.include]: failed to open stream: No such file or directory in /nfs/c01/h06/mnt/45373/domains/dev.bowdenweb.com/html/css/ex/tta/index.php on line 144

Warning: include() [function.include]: Failed opening '/home/45373/domains/dev.bowdenweb.com/html/contents.php' for inclusion (include_path='.:/usr/local/php-5.3.29/share/pear') in /nfs/c01/h06/mnt/45373/domains/dev.bowdenweb.com/html/css/ex/tta/index.php on line 144

Warning: include(/home/45373/domains/dev.bowdenweb.com/html/disqus.php) [function.include]: failed to open stream: No such file or directory in /nfs/c01/h06/mnt/45373/domains/dev.bowdenweb.com/html/css/ex/tta/index.php on line 161

Warning: include() [function.include]: Failed opening '/home/45373/domains/dev.bowdenweb.com/html/disqus.php' for inclusion (include_path='.:/usr/local/php-5.3.29/share/pear') in /nfs/c01/h06/mnt/45373/domains/dev.bowdenweb.com/html/css/ex/tta/index.php on line 161

Warning: include(/home/45373/domains/dev.bowdenweb.com/html/footer.php) [function.include]: failed to open stream: No such file or directory in /nfs/c01/h06/mnt/45373/domains/dev.bowdenweb.com/html/css/ex/tta/index.php on line 186

Warning: include() [function.include]: Failed opening '/home/45373/domains/dev.bowdenweb.com/html/footer.php' for inclusion (include_path='.:/usr/local/php-5.3.29/share/pear') in /nfs/c01/h06/mnt/45373/domains/dev.bowdenweb.com/html/css/ex/tta/index.php on line 186