SlideShare une entreprise Scribd logo
1  sur  69
Télécharger pour lire hors ligne
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

Contenu connexe

Similaire à Css3 transitions and animations + graceful degradation with jQuery

20111129 modernizr
20111129 modernizr20111129 modernizr
20111129 modernizrbrooky-yen
 
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.comapplicake
 
Add Some Awesome-Sauce
Add Some Awesome-SauceAdd Some Awesome-Sauce
Add Some Awesome-Saucedavist11
 
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 Anna Migas
 
SnapyX
SnapyXSnapyX
SnapyXekino
 
CSS3: The Next Generation Of Style
CSS3: The Next Generation Of StyleCSS3: The Next Generation Of Style
CSS3: The Next Generation Of StylejbellWCT
 
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 CSS3Helder da Rocha
 
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...Codemotion
 
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 ModernizrMichael Enslow
 
JS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-NativeJS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-NativeJSFestUA
 
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 Anna Migas
 
HTML5, CSS3, and other fancy buzzwords
HTML5, CSS3, and other fancy buzzwordsHTML5, CSS3, and other fancy buzzwords
HTML5, CSS3, and other fancy buzzwordsMo Jangda
 
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...Chris Fregly
 
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 AIData Con LA
 
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 FlashThomas Fuchs
 

Similaire à 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
 

Plus de Andrea Verlicchi

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.pdfAndrea Verlicchi
 
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.pdfAndrea Verlicchi
 
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.pptxAndrea Verlicchi
 
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.0Andrea Verlicchi
 
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 standardAndrea Verlicchi
 
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 SassAndrea Verlicchi
 
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 FaenzaAndrea Verlicchi
 

Plus de 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
 

Dernier

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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)wesley chun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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...Drew Madelung
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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 RobisonAnna Loughnan Colquhoun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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.pdfUK Journal
 
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?Igalia
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Dernier (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer 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
 
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?
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

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