SlideShare ist ein Scribd-Unternehmen logo
1 von 69
Downloaden Sie, um offline zu lesen
CSS 3
Transitions and Animations




Graceful degradation with jQuery
About me
   • Andrea Verlicchi
   • Gruppo Euris - Bologna
   • Senior Front End
     Developer & Team
     Leader in Yoox Group
   • www.andreaverlicchi.eu
       verlok
NEW IN CSS 3
NEW IN CSS 3

   • New styles
   • Transforms
   • Transitions
   • Animations
New styles

 • border-radius
 • box-shadow
 • text-shadow
 • rgba / hsla
 • gradients
Transforms

 • scale
 • rotate
 • skew
 • translate 2D
 • translate 3D
Transitions




Change between states gradually in time
Animations




Automatic transition through states
 (keyframes) defined in a time line
Any doctype


CSS 3 works on any version of x/html
 HTML 5, HTML 4, XHTML 1, etc.
BROWSERS
BROWSER SUPPORT



10+         All   All   All         12+



  IE 9: Basic            IE 8, 7, 6: No
Browser stats (Oct 2012)
                       CHROME
            INTERNET EXPLORER
             FIREFOX
   SAFARI
   OPERA
   OTHER
Browser versions (Oct 12)

                  IE 9
           IE 8



    IE 7

   IE 6
Mobile browsers (Oct 12)
                            ANDROID

                          IPHONE
                         OPERA
                NOKIA
            UC BROWSER
        NETFRONT
        BLACKBERRY
      IPOD                      +
    DOLFIN                    SAFARI
Windows 8 + IE 10 Release
BROWSERS ARE
READY FOR CSS 3
CSS 3
TRANSITIONS
     vs
 JAVASCRIPT
ANIMATIONS
Low effort
BETTER RESULTS
     No queue
      Users don’t have to wait                          GPU acceleration
                                           Best performance
                                              Expecially on mobile devices


Consistent layout
CSS-driven final state
                                              Browser-triggered
                                                    animations
                                                           Zoom, MQ switch
           Asynchronous
           They run on a separate thread
Development time
   (and maintenance)
IE 8 + 9 will be around for a while.
Do we have to write twice the code
       to do the same thing?
NO
Progressive enhancement


Do you really want to / need to replicate
EVERY effect you CAN create using CSS
              transitions?
Low redundancy


If you really need to replicate an effect,
   the code redundancy is VERY LOW
HOW DO WE DO IT?
A transition is about animating the change
    of value of one or more element
        properties in a given time.
SO WE NEED TO...
• Consider an element in the DOM
• Define what element properties to
    transition
•   Define in how much time the
    properties will change
•   Define a final state for the element
    properties
CONSIDER AN ELEMENT IN
      THE DOM

        Using a CSS selector.
    I.g.: All the links in the page


    a {}
DEFINE IN HOW MUCH TIME
 THE PROPERTIES CHANGE

 Using the “transition-duration” property


       a {
             transition-duration: 1s;
       }
DEFINE WHAT ELEMENT
PROPERTIES TO TRANSITION

 Using the “transition-property” property

       a {
             transition-duration: 1s;
             transition-property: color;
       }
DEFINE A FINAL STATE FOR
THE ELEMENT PROPERTIES

     3 possible ways:
     • Using an auto-applied
       pseudo class
     • Using a class
     • Using Javascript
FINAL STATE WITH A
   PSEUDO-CLASS

    a:hover {
        color: red;
    }




The link color will transition to red
        on mouseover state
FINAL STATE WITH A CLASS


       a.selected {
           color: black;
       }




The link color will transition to black when
      the selected class is applied to it
FINAL STATE USING
       JAVASCRIPT


       $(‘a’).css(‘color’, ‘blue’);




The link color will transition to blue when
       this line of code is executed
DEMO
WHAT ABOUT OLD IE
   VERSIONS?
GRACEFUL
        DEGRADATION

   DESIGN FOR MODERN BROWSERS
but make your site work perfectly for OLDER
     VERSIONS that are still out there
             (maybe with less effects)
GRACEFUL
     DEGRADATION
     in TRANSITIONS

In which cases should we implement
     a fallback, javascript based
              transition?
WE SHOULD NOT
   When the transitions are merely for
“coolness”, or they may negatively affect site
    load time or runtime performance
WE SHOULD
  When transitions are useful for the site
comprehension, usability, to attract users, etc.
DETECTING
BROWSER FEATURES
USE MODERNIZR!


• Go to http://modernizr.com/
• Download development
  version of Modernizr
• Copy it in your site folder
• Link it in your site header
WHAT MODERNIZR DOES:

For each result:
• It creates a boolean property of a global
   object called Modernizr
• It adds a css class to the html element of
   the page
WHAT MODERNIZR DOES:

Example:
• Modernizr.csstransitions (true/false)

• <html class=“csstransitions”>
  note: the negative result no-csstransitions
WHAT YOU CAN DO:

• JS: Create alternative lines of Javascript code
  to manage CSS transitions / Javascript
  transitions
• CSS: Manage exceptions depending on the
  browser support to CSS transitions
EXAMPLE OF JS FALLBACK

var newLeft = SOME_VALUE;

// Set the new left if browser can handle css transitions
// else animate it the left property
if (Modernizr.csstransitions) {
    this.bannerContainer.css({ left: newLeft });
} else {
    this.bannerContainer.animate({ left: newLeft }, 750);
}
EXAMPLE OF CSS FALLBACK


 #someBox {
     background-color: rgba(255, 255, 255, 0.5);
 }

 html.no-rgba #someBox {
     background-image: url(‘../img/white_50_percent.png’);
 }
DEMO
WHAT ABOUT
ANIMATIONS?
WHAT ARE ANIMATIONS


 Animations allow us to define states in time
  (keyframes) and transition through them
CSS ANIMATIONS

• Name an animation
• Define a set of keyframes
• Define the CSS properties for each frame
• Apply the animation in time
= Automatic transition bewteen keyframes
DECLARATION
Defining the animation “bounceThenFly”


@keyframes   bounceThenFly {
    0%       { background-position:   -13px 42px }
    10%      { background-position:   -7px 30px }
    20%      { background-position:   -13px 42px }
    30%      { background-position:   -7px 30px }
    40%      { background-position:   -13px 42px }
    50%      { background-position:   40px -60px }
    50.01%   { background-position:   -35px 120px }
    98%      { background-position:   -13px 42px }
}
DECLARATION
    (each keyframe can be more complex)

@keyframes anotherAnimation {

      // ...

      50% {
          background-color: red;
          color: white;
          text-shadow: 0 0 10px black;
      }

      // ...
}
USAGE
The #rocket element will use the animation
“bounceThenFly” during a time of 5 seconds,
         and repeat it infinitely

     #rocket {
       animation-name: bounceThenFly;
       animation-duration: 5s;
       animation-iteration-count: infinite;
     }
USAGE
Less characters = happier coders & lighter CSS



      #rocket {
        animation: bounceThenFly 5s infinite;
      }
USAGE
Less characters = happier coders & lighter CSS


        #rocket {
          animation: bounceThenFly 5s infinite;
        }




 animation-name   animation-duration   animation-iteration-count
DEMO
INTO THE WILD
VENDOR PREFIXES

For the CSS rules that are still to be defined as a
   standard, we need to use vendor-prefixes
VENDOR PREFIXES
For the CSS rules that are still to be defined as a
   standard, we need to use vendor-prefixes




-webkit-        -moz-          -ms-           -o-

                 MARCH 2012
VENDOR PREFIXES
For the CSS rules that are still to be defined as a
   standard, we need to use vendor-prefixes




            -webkit-             -o-

               OCTOBER 2012
VENDOR PREFIXES
For the CSS rules that are still to be defined as a
   standard, we need to use vendor-prefixes




                    -webkit-

                  ____ 2013 ?
Option A
 Manually duplicate the code From:
transition: color 500ms ease-in-out;



                      To:
-webkit-transition: color 500ms ease-in-out;
-o-transition: color 500ms ease-in-out;
transition: color 500ms ease-in-out;
Option B
Use a script to do it automatically


      Client-side: PrefixFree
  http://leaverou.github.com/prefixfree/


       Server-side: Prefixer
    http://cssprefixer.appspot.com/
RESUME
TRANSITIONS

• FOR LITTLE GRAPHIC TRANSITIONS
  without detect and fallback
• FOR RELEVANT GRAPHIC TRANSITIONS
  with Javascript detect and fallback
• FOR EVERY TRANSITION on MOBILE
  no real need of detect and fallback
ANIMATIONS

• TO CREATE ANIMATED ELEMENTS IN SITES
  i.g. banners, call-to-action buttons, logos,
  graphical background elements
• SEE:
  http://2012.fromthefront.it
• They make a more pleasant
 user experience for users
 with modern browsers
• They are optimized for
 mobile devices
@verlok
www.andreaverlicchi.eu

Weitere ähnliche Inhalte

Ähnlich wie Css3 transitions and animations + graceful degradation with jQuery

SnapyX
SnapyXSnapyX
SnapyX
ekino
 

Ähnlich wie Css3 transitions and animations + graceful degradation with jQuery (20)

20111129 modernizr
20111129 modernizr20111129 modernizr
20111129 modernizr
 
Html5 more than just html5 v final
Html5  more than just html5 v finalHtml5  more than just html5 v final
Html5 more than just html5 v final
 
slides-students-C04.pdf
slides-students-C04.pdfslides-students-C04.pdf
slides-students-C04.pdf
 
A brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.com
A brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.comA brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.com
A brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.com
 
CSS and CSS3
CSS and CSS3CSS and CSS3
CSS and CSS3
 
Add Some Awesome-Sauce
Add Some Awesome-SauceAdd Some Awesome-Sauce
Add Some Awesome-Sauce
 
Sexy React Stack
Sexy React StackSexy React Stack
Sexy React Stack
 
HalfStack London - Make Your Animations Perform Well
HalfStack London - Make Your Animations Perform Well HalfStack London - Make Your Animations Perform Well
HalfStack London - Make Your Animations Perform Well
 
SnapyX
SnapyXSnapyX
SnapyX
 
SnapyX - ParisJS
SnapyX - ParisJSSnapyX - ParisJS
SnapyX - ParisJS
 
CSS3: The Next Generation Of Style
CSS3: The Next Generation Of StyleCSS3: The Next Generation Of Style
CSS3: The Next Generation Of Style
 
JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3
 
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
 
It's a Mod World - A Practical Guide to Rocking Modernizr
It's a Mod World - A Practical Guide to Rocking ModernizrIt's a Mod World - A Practical Guide to Rocking Modernizr
It's a Mod World - A Practical Guide to Rocking Modernizr
 
JS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-NativeJS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-Native
 
Make Your Animations Perform Well - JS Conf Budapest 2017
Make Your Animations Perform Well - JS Conf Budapest 2017 Make Your Animations Perform Well - JS Conf Budapest 2017
Make Your Animations Perform Well - JS Conf Budapest 2017
 
HTML5, CSS3, and other fancy buzzwords
HTML5, CSS3, and other fancy buzzwordsHTML5, CSS3, and other fancy buzzwords
HTML5, CSS3, and other fancy buzzwords
 
PipelineAI + AWS SageMaker + Distributed TensorFlow + AI Model Training and S...
PipelineAI + AWS SageMaker + Distributed TensorFlow + AI Model Training and S...PipelineAI + AWS SageMaker + Distributed TensorFlow + AI Model Training and S...
PipelineAI + AWS SageMaker + Distributed TensorFlow + AI Model Training and S...
 
Optimizing, Profiling, and Deploying High Performance Spark ML and TensorFlow AI
Optimizing, Profiling, and Deploying High Performance Spark ML and TensorFlow AIOptimizing, Profiling, and Deploying High Performance Spark ML and TensorFlow AI
Optimizing, Profiling, and Deploying High Performance Spark ML and TensorFlow AI
 
I Can't Believe It's Not Flash
I Can't Believe It's Not FlashI Can't Believe It's Not Flash
I Can't Believe It's Not Flash
 

Mehr von Andrea Verlicchi

Mehr von Andrea Verlicchi (7)

How and Why ($) to improve web performance.pdf
How and Why ($) to improve web performance.pdfHow and Why ($) to improve web performance.pdf
How and Why ($) to improve web performance.pdf
 
Come e perché ($) migliorare le prestazioni web.pdf
Come e perché ($) migliorare le prestazioni web.pdfCome e perché ($) migliorare le prestazioni web.pdf
Come e perché ($) migliorare le prestazioni web.pdf
 
Come e perché ($) migliorare le prestazioni web - Aprile 2023.pptx
Come e perché ($) migliorare le prestazioni web - Aprile 2023.pptxCome e perché ($) migliorare le prestazioni web - Aprile 2023.pptx
Come e perché ($) migliorare le prestazioni web - Aprile 2023.pptx
 
2022.04 - CSS Day IT - Images Optimisation 4.0
2022.04 - CSS Day IT - Images Optimisation 4.02022.04 - CSS Day IT - Images Optimisation 4.0
2022.04 - CSS Day IT - Images Optimisation 4.0
 
Responsive images, an html 5.1 standard
Responsive images, an html 5.1 standardResponsive images, an html 5.1 standard
Responsive images, an html 5.1 standard
 
Agile CSS development with Compass and Sass
Agile CSS development with Compass and SassAgile CSS development with Compass and Sass
Agile CSS development with Compass and Sass
 
Sviluppo CSS agile con SASS e Compass - CSS Day 2015 Faenza
Sviluppo CSS agile con SASS e Compass - CSS Day 2015 FaenzaSviluppo CSS agile con SASS e Compass - CSS Day 2015 Faenza
Sviluppo CSS agile con SASS e Compass - CSS Day 2015 Faenza
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

Css3 transitions and animations + graceful degradation with jQuery

  • 1. CSS 3 Transitions and Animations Graceful degradation with jQuery
  • 2. About me • Andrea Verlicchi • Gruppo Euris - Bologna • Senior Front End Developer & Team Leader in Yoox Group • www.andreaverlicchi.eu verlok
  • 4. NEW IN CSS 3 • New styles • Transforms • Transitions • Animations
  • 5. New styles • border-radius • box-shadow • text-shadow • rgba / hsla • gradients
  • 6. Transforms • scale • rotate • skew • translate 2D • translate 3D
  • 8. Animations Automatic transition through states (keyframes) defined in a time line
  • 9. Any doctype CSS 3 works on any version of x/html HTML 5, HTML 4, XHTML 1, etc.
  • 11. BROWSER SUPPORT 10+ All All All 12+ IE 9: Basic IE 8, 7, 6: No
  • 12. Browser stats (Oct 2012) CHROME INTERNET EXPLORER FIREFOX SAFARI OPERA OTHER
  • 13. Browser versions (Oct 12) IE 9 IE 8 IE 7 IE 6
  • 14. Mobile browsers (Oct 12) ANDROID IPHONE OPERA NOKIA UC BROWSER NETFRONT BLACKBERRY IPOD + DOLFIN SAFARI
  • 15. Windows 8 + IE 10 Release
  • 17. CSS 3 TRANSITIONS vs JAVASCRIPT ANIMATIONS
  • 19. BETTER RESULTS No queue Users don’t have to wait GPU acceleration Best performance Expecially on mobile devices Consistent layout CSS-driven final state Browser-triggered animations Zoom, MQ switch Asynchronous They run on a separate thread
  • 20. Development time (and maintenance)
  • 21. IE 8 + 9 will be around for a while. Do we have to write twice the code to do the same thing?
  • 22. NO
  • 23. Progressive enhancement Do you really want to / need to replicate EVERY effect you CAN create using CSS transitions?
  • 24. Low redundancy If you really need to replicate an effect, the code redundancy is VERY LOW
  • 25. HOW DO WE DO IT?
  • 26. A transition is about animating the change of value of one or more element properties in a given time.
  • 27. SO WE NEED TO... • Consider an element in the DOM • Define what element properties to transition • Define in how much time the properties will change • Define a final state for the element properties
  • 28. CONSIDER AN ELEMENT IN THE DOM Using a CSS selector. I.g.: All the links in the page a {}
  • 29. DEFINE IN HOW MUCH TIME THE PROPERTIES CHANGE Using the “transition-duration” property a { transition-duration: 1s; }
  • 30. DEFINE WHAT ELEMENT PROPERTIES TO TRANSITION Using the “transition-property” property a { transition-duration: 1s; transition-property: color; }
  • 31. DEFINE A FINAL STATE FOR THE ELEMENT PROPERTIES 3 possible ways: • Using an auto-applied pseudo class • Using a class • Using Javascript
  • 32. FINAL STATE WITH A PSEUDO-CLASS a:hover { color: red; } The link color will transition to red on mouseover state
  • 33. FINAL STATE WITH A CLASS a.selected { color: black; } The link color will transition to black when the selected class is applied to it
  • 34. FINAL STATE USING JAVASCRIPT $(‘a’).css(‘color’, ‘blue’); The link color will transition to blue when this line of code is executed
  • 35. DEMO
  • 36. WHAT ABOUT OLD IE VERSIONS?
  • 37. GRACEFUL DEGRADATION DESIGN FOR MODERN BROWSERS but make your site work perfectly for OLDER VERSIONS that are still out there (maybe with less effects)
  • 38. GRACEFUL DEGRADATION in TRANSITIONS In which cases should we implement a fallback, javascript based transition?
  • 39. WE SHOULD NOT When the transitions are merely for “coolness”, or they may negatively affect site load time or runtime performance
  • 40. WE SHOULD When transitions are useful for the site comprehension, usability, to attract users, etc.
  • 42. USE MODERNIZR! • Go to http://modernizr.com/ • Download development version of Modernizr • Copy it in your site folder • Link it in your site header
  • 43. WHAT MODERNIZR DOES: For each result: • It creates a boolean property of a global object called Modernizr • It adds a css class to the html element of the page
  • 44. WHAT MODERNIZR DOES: Example: • Modernizr.csstransitions (true/false) • <html class=“csstransitions”> note: the negative result no-csstransitions
  • 45. WHAT YOU CAN DO: • JS: Create alternative lines of Javascript code to manage CSS transitions / Javascript transitions • CSS: Manage exceptions depending on the browser support to CSS transitions
  • 46. EXAMPLE OF JS FALLBACK var newLeft = SOME_VALUE; // Set the new left if browser can handle css transitions // else animate it the left property if (Modernizr.csstransitions) { this.bannerContainer.css({ left: newLeft }); } else { this.bannerContainer.animate({ left: newLeft }, 750); }
  • 47. EXAMPLE OF CSS FALLBACK #someBox { background-color: rgba(255, 255, 255, 0.5); } html.no-rgba #someBox { background-image: url(‘../img/white_50_percent.png’); }
  • 48. DEMO
  • 50. WHAT ARE ANIMATIONS Animations allow us to define states in time (keyframes) and transition through them
  • 51. CSS ANIMATIONS • Name an animation • Define a set of keyframes • Define the CSS properties for each frame • Apply the animation in time = Automatic transition bewteen keyframes
  • 52. DECLARATION Defining the animation “bounceThenFly” @keyframes bounceThenFly { 0% { background-position: -13px 42px } 10% { background-position: -7px 30px } 20% { background-position: -13px 42px } 30% { background-position: -7px 30px } 40% { background-position: -13px 42px } 50% { background-position: 40px -60px } 50.01% { background-position: -35px 120px } 98% { background-position: -13px 42px } }
  • 53. DECLARATION (each keyframe can be more complex) @keyframes anotherAnimation { // ... 50% { background-color: red; color: white; text-shadow: 0 0 10px black; } // ... }
  • 54. USAGE The #rocket element will use the animation “bounceThenFly” during a time of 5 seconds, and repeat it infinitely #rocket { animation-name: bounceThenFly; animation-duration: 5s; animation-iteration-count: infinite; }
  • 55. USAGE Less characters = happier coders & lighter CSS #rocket { animation: bounceThenFly 5s infinite; }
  • 56. USAGE Less characters = happier coders & lighter CSS #rocket { animation: bounceThenFly 5s infinite; } animation-name animation-duration animation-iteration-count
  • 57. DEMO
  • 59. VENDOR PREFIXES For the CSS rules that are still to be defined as a standard, we need to use vendor-prefixes
  • 60. VENDOR PREFIXES For the CSS rules that are still to be defined as a standard, we need to use vendor-prefixes -webkit- -moz- -ms- -o- MARCH 2012
  • 61. VENDOR PREFIXES For the CSS rules that are still to be defined as a standard, we need to use vendor-prefixes -webkit- -o- OCTOBER 2012
  • 62. VENDOR PREFIXES For the CSS rules that are still to be defined as a standard, we need to use vendor-prefixes -webkit- ____ 2013 ?
  • 63. Option A Manually duplicate the code From: transition: color 500ms ease-in-out; To: -webkit-transition: color 500ms ease-in-out; -o-transition: color 500ms ease-in-out; transition: color 500ms ease-in-out;
  • 64. Option B Use a script to do it automatically Client-side: PrefixFree http://leaverou.github.com/prefixfree/ Server-side: Prefixer http://cssprefixer.appspot.com/
  • 66. TRANSITIONS • FOR LITTLE GRAPHIC TRANSITIONS without detect and fallback • FOR RELEVANT GRAPHIC TRANSITIONS with Javascript detect and fallback • FOR EVERY TRANSITION on MOBILE no real need of detect and fallback
  • 67. ANIMATIONS • TO CREATE ANIMATED ELEMENTS IN SITES i.g. banners, call-to-action buttons, logos, graphical background elements • SEE: http://2012.fromthefront.it
  • 68. • They make a more pleasant user experience for users with modern browsers • They are optimized for mobile devices