Webkit CSS Transitions – pretty cool stuff
I recently read somewhere about developing web applications for the iPhone / Android browsers that you shouldn’t use Javascript Frameworks (e.g. jQuery) for animation in your web apps but instead use CSS3 transitions. I had no idea what these where, so had to look it up. Turns out it’s pretty much a WebKit only thing, but that’s fine for iPhone (Safari) and Android (Chrome) Browsers.
But what is it? Simply put, it’s a way to create a transition between to CSS states (hope that cleared everything up for you!)
Better, an example: You have two CSS rules for an element, say a link, and for it’s :hover state. like this:
background:#eee;
color:#333;
text-decoration:none;
padding:5px 10px;
border:2px solid #333;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
a:hover {
background:#333;
color:#eee;
}
Now usually, the browser would switch instantly between these two states, but with transitions we can slow it down into a smooth animation.
We can specify which propertys to transition and which to allow to change instantly. Here we can transition in the background and color properties.
background:#eee;
color:#333;
text-decoration:none;
padding:5px 10px;
border:2px solid #333;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
/* Add the transition properties! */
-webkit-transition-property: background-color, color;
-webkit-transition-duration: 600ms;
/* you can control the acceleration curve here */
-webkit-transition-timing-function: ease-in-out;
}
a:hover {
background:#333;
color:#eee;
}
Here’s two links, the they are identical except that the second has the transisions applied and if you’re using a WebKit based browser then it will fade nicely between states.
I will flick between states. Do I fade or do I flick?
Next time I’ll go into a bit more detail and show how using CSS Transforms as well we can make an OSX Dock style menu using CSS alone!
Do you know if webkit will support -border-radius and outline of the same element? I have tried this, but it appears as if the outline is still only a square?
Mike Shaver
15 May 09 at 20:58 edit_comment_link(__('Edit', 'sandbox'), ' ', ''); ?>
I don’t know. I guess you would try -outline-radius but I haven’t tested that yet. Outline and border are definitely two very different beasts.
Chris
17 May 09 at 10:30 edit_comment_link(__('Edit', 'sandbox'), ' ', ''); ?>
Damnnn…. Did see that coming
) CSS property transitions – AWESOME !!!
Thanks for sharing this…
QR Coder
12 Aug 09 at 10:30 edit_comment_link(__('Edit', 'sandbox'), ' ', ''); ?>