Archive for the ‘WebKit’ tag
More WebKit Goodies – CSS Transforms and Transitions – the OSX Dock example
As promised last time, I here we will discuss the transforms in WebKit, and how they can be used to create interactive applications without Javascript (for animation that is – we still need it for AJAX, etc.)
Tranforms have been implemented on a few browser using proprietary syntax, and the same is true of WebKit. As we shall see further down the article though, the WebKit transitions make them so much more powerful.
But what are they? They modify an element, without displacing it’s original setting within the document, which means we can move it about and the spacing doesn’t change.
Remember these will only work in WebKit based browsers, for example Safari for Mac, Chrome for Windows or Midori for Linux
An example: how about rotation.
element:hover {
-webkit-transform:rotate(180deg);
}
Not very exciting, but combine this with a transition! (Try putting you mouse in the middle of the box for best effect)
element:hover {
-webkit-transform:rotate(180deg);
}
element {
-webkit-transition:-webkit-transform 1s linear
}
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!