HTML5 Zone is brought to you in partnership with:

John Esposito edits Refcardz at DZone, while writing a dissertation on ancient Greek philosophy and raising two cats. In a previous life he was a database developer and network administrator. John is a DZone Zone Leader and has posted 320 posts at DZone. You can read more from them at their website. View Full User Profile

CSS3 Transitions, Hover Effects, and Two Different Kinds of Interactivity

  • submit to reddit

This CSS3 hover tutorial caught my eye -- but also fired a recent designer's rant in my memory. Why do these hover effects, by Alessio Atzeni, look cooler than these?

The former is animated, of course, while the latter is not. Animation alone increases the sense of interactivity -- from infancy, even. But then what's the difference between this animation (flying zoom) and this one (sideways slide)? The CSS elements themselves are straightforward (scale and translate with ease-in-out) -- but why use one and not the other?

These are designers' questions, I suppose, and accordingly rather beyond me. But comparing these two CSS hover tutorials (1,2), especially the multiple transition&animation variations demoed here, gives a clear sense of how CSS3 allows a small change in the developer's code to make a really significant difference in the user's experience.

Alessio's 'true bounce effect' in Example 8 is particularly neat. At the heart is this keyframe rule -- easy to understand in principle, but remarkably well executed:

@keyframes bounceY {
2	    0% { transform: translateY(-205px);}
3	    40% { transform: translateY(-100px);}
4	    65% { transform: translateY(-52px);}
5	    82% { transform: translateY(-25px);}
6	    92% { transform: translateY(-12px);}
7	    55%, 75%, 87%, 97%, 100% { transform: translateY(0px);}
8	}

The trick lies, obviously, in the exact relation between the timing percents and the translationY distances. Alessio doesn't explain exactly how he selected these numbers, but they were certainly well-chosen.

These are the kinds of super-concrete details I find especially helpful in a tutorial like this -- where individual tips are concrete, but surrounded by a large enough number of variations that very different pages can benefit from a considerable variety of user experiences produced by fairly similar bits of code. You might want to keep this tutorial page as a go-to guide for high-quality and easy-to-code CSS3 transition and animation effects.