May 052010
 

CSS3 transitions are now available on Firefox, Chrome, Safari, Opera and … IE9!, and it’s awesome.

CSS Transitions allows property changes in CSS values to occur smoothly over a specified duration.

Javascript is not anymore required for simple animation.

Specifically, we don’t need Javascript to manage animation with setInterval or with any library like jQuery.animate : Forget the animation management, stay focused on the real work.

In this article, I will try to explain why and how using css3-transition with some examples.

Why ?

  • It’s simple and smart : adding one line of css code.
  • It let the browser rendering animation instead of using javascript complex code. You don’t have to worry about animation and performance. So you can stay focused on real part of your project.
  • It’s cleaner than some javascript animation implementation because you don’t modify style attribute during animations. So, it’s also probably more efficient.
  • Degradation is great. If your browser doesn’t support CSS Transition, it’s not really bad, only the animation is not available. Other behaviors aren’t alterate. For example, imagine a photo slide-show with zoom effect when changing photo. With an old browser, photos are just instantly zoomed without animation. That’s not bad.
  • And off course, It’s standard.

How ?

CSS Transition are extremely simply to use.

transition-duration

Basically, you set a css time properties in a css selector like -moz-transition-duration: 1s; for mozilla. This time define the animation duration. Browser will determine the transition between this selector and a descendant selector.

Not that css3 transition is currently in draft mode, so there are multiple property for each browser (the prefix change).

For Firefox (3.7+), Chrome (and other webkit browser) and Opera, you have to use :

-moz-transition-duration: 1s;
-webkit-transition-duration: 1s;
-o-transition-duration: 1s;

Don’t panic, in the future (on CSS3 release), only one property will be used.

Example

.box {
  -moz-transition-duration: 1s;
  -webkit-transition-duration: 1s;
  -o-transition-duration: 1s;

  margin: 10px;
  background-color: red;
}
.box:hover {
  margin: 50px;
  background-color: green;
}

On mouse over the .box, during one second : margin will move from 10px to 50px and background-color will move from red to green. That’s all!

transition-property

You can also specify the name of the CSS property to which the transition is applied.

For instance, color, width, opacity, …

Like this

  -moz-transition-property: margin, background-color;
  -webkit-transition-property: margin, background-color;
  -o-transition-property: margin, background-color;

Others properties

More properties are available to specify more deeply transition effects. Retrieve them on CSS Transitions Working Draft.

  • transition-timing-function
  • transition-delay

Examples

Here are some CSS transition examples.

Box effects

A box with color, text, shapes transformation.

Letters

Letters animation.

Slider

Image slider.

Navigation bar

Navigation bar.

More examples soon…

  • http://www.pagerank-seo.com Robert Visser

    Great examples. Thanks. On the slider to increase usability and decrease cashe, I’d add play/pause button(s).

    • http://grenlibre.fr/ Gaetan

      Great idea, thanks for feedback.

      I will continue to add some others effects. Moreover, I will try to resolve the image caching problem.

  • http://www.zirro.se Magne Andersson

    They are great indeed, but you make it sound as support has been added recently. In fact, it’s been supported since early October 2009 :-)

    • http://grenlibre.fr/ Gaetan

      Yes, I know it’s not really recent, but FF3.7 will be released soon, so I wanted to do yet others demos about CSS3 Transition. Moreover, to be honest with you, I just begin to experiment CSS3 Transition (but I heard about it a while ago).

      Thanks for feedback.

  • Andre

    Typo in your post title: “CSS3 *Transition* available on Firefox 3.7″ — should be Transitions — plural.

  • Andre

    …Same problem with the URL. But, if you fix that, remember to redirect.

    • http://grenlibre.fr/ Gaetan

      Thanks. It’s fixed.

  • Pingback: CSS3 Transitions available on Firefox 3.7 | Webstuffshare.com - Worth Sharing Bookmarked Webstuff

  • http://freefont.lipssclub.com/font41.html free font

    hello!
    thank you very much for sharing the script ^^!
    very much appreciated :D

  • Pingback: Bram.us » CSS3 Transitions available on Firefox 3.7

  • Pingback: Vidéo: Les transitions CSS3 : Un exemple de diaporama d’images « Informatique et logiciel libre

  • http://les-ouvriers-habitat.fr/ Arsinoé Pierre

    J’aime beaucoup votre blog et ce dont vous nous parlez. Bravo pour votre blog et votre aide

  • http://www.aexm.fr site internet grenoble

    merci pour cet article

    et bien ca va faire encore du boulot pour intégrer ca dans mes blogs / sites wordpress !

    je vais le gain en page load que cela apporte sur les menu ou image ! reste à savoir si il y des plugin wordpress qui vont intégrer cela !

    merci encore pour les infos !

    Sebastien

  • http://www.buzzfeed.com/earnestmayomo/cash-loan-till-payday-1tyu Margarett Kant

    I’ve recently started a website, the information you provide on this site has helped me tremendously. Thanks for all of your time & work.

  • http://www.vaillancecredit.fr forum pret immobiliers

    très bon blog! ces infos sont très utiles! merci beaucoup. :)

  • http://www.fabian-design.de webdesigner

    does this work on 4.0?

    • http://grenlibre.fr/ Gaetan

      Sure!
      Today, It’s work on FF4+, Chrome, Safari, and… IE 9

  • http://beckyrother.com/portfolio becky

    c’était très utile ! merci mille fois :)

  • http://www.maccagno.fr immobilier grenoble

    good idea, thanks for feedback.
    it’s works on firefox 4, and safari !

    AC

  • http://www.devisdetective.com detective prive

    Je confirme cela marche du tonnerre, merci pour le tuyau !

  • Pingback: Простая анимация без JavaScript — пояснение, зачем и, главное — как?!