SlideShare une entreprise Scribd logo
1  sur  52
Mastering CSS
animations and
transitions
About me
•

Hi, I’m GoodBytes

•

I teach web development to my Interactive Multimedia Design students in
Mechelen, Belgium. More info at http://www.weareimd.be

•

I’m a freelance web developer, get in touch via http://www.goodbytes.be
or just shoot me a message on Twitter @GoodBytes
About this slide deck
•

I used this slide deck during a workshop I gave about CSS
animations and uploaded them upon request

•

The slides will probably lose about 80% of their meaning without the
accompanying explanation and demo’s given during the workshop

•

All screenshots you see are actually video’s to demo an animation.
Like I said, this deck will lose about 80% of its meaning without the
videos and matching explanation

•

If you’d like to get a thorough workshop about CSS animations, feel
free to get in touch with me at http://www.goodbytes.be
When was the last time something
on the web delighted you?
http://uxrave.com/
http://uxrave.com/
Live icon

http://dribbble.com/pattern
http://space.angrybirds.com/launch/

http://joelb.me/scrollpath/
http://dribbble.com/shots/419244-Login-animation
http://www.smashingmagazine.com
animations, transitions,
transformations,
translates
you will be creating animations
where you call a transform that
uses a translate function
transitions
•

an animation between changes

•

properties we want to animate need to be defined explicitly

•

can be triggered by adding classes of using pseudo-selectors
like :hover

•

example 1: change button color on hover (and animate it!)

•

example 2: motion by changing the position of an element
transitions

•

transition: property duration timing-function delay;

transition: background-color 5s linear 1s;
<div id="circle"></div>!

#circle!
{!
! width: 200px;!
! height: 200px;!
! background-color: white;!
! border-radius: 50%;!
! transition: height 1s linear, width 1s linear, background-color 5s linear 1s;!
}!
!

#circle:hover!
{!
! height: 300px;!!
! width: 300px;!
! background-color: red;!
}!
transitions
•

transitioning properties like left and margin cause a browser to
recalculate styles every frame.

•

repaints (visibility) & reflows (layout)

•

can be bad for performance, especially on slower mobile
devices

•

solution: use CSS transformations to enable GPU hardware
acceleration where appropriate
using translate

using top/left coordinates
transform(ation)s
•

physically change the look of an element

•

example 1: change the size of an element

•

example 2: rotate/spin an element

•

example 3: move an element

•

can be 2D or 3D
transitions with transforms
<div id="shape"></div>!
#shape!
{!
! width: 150px;!
! height: 150px;!
! background-color: #e74c3c;!
! transition: -webkit-transform 1s;!
}!
!

#shape:hover!
{!
! -webkit-transform: scale(2) translateY(100px) rotate(45deg);!
}!
you will be creating animations
where you call a transform that
uses a translate function
animations vs.
transitions
transitions

animations

go from A to B

got from A (over B, C, D, E) to … via keyframes

need to be triggered somehow

can start automatically and loop

you have to be formal about which properties
you want to animate

Transforms are ways to change your shapes with scale(), rotate(), skew(),…
2D transforms
•

translate()

•

rotate()

•

scale()

•

skew()

•

matrix() = all of the above
<div id="square"></div>!

#square!
{!
! width: 200px;!
! height: 200px;!
! background-color: white;!
! border-radius: 10%;!
! margin-left: 0px;!
! transition: -webkit-transform 0.5s;!
}!
!

#square:hover, #square.automatic!
{!
! -webkit-transform: scale(2.2) translate(200px, 100px) skew(10deg)
rotate(45deg);!
}!
animations

•

keyframes

•

can loop

•

can start automatically
<div id="square" class="automatic"></div>!

.automatic!
{!
! -webkit-animation: moveIt 2s infinite;!
}!

@-webkit-keyframes moveIt!
{!
! 0%
{ }!
! 25% { -webkit-transform: rotate(45deg);}!
! 50% { left:50%; top: 50%; -webkit-transform: scale(2.5) rotate(45deg);}!
! 100% { -webkit-transform: rotate(0deg);}!
}!
3D transforms
•

-webkit-transform: perspective(300px) rotateY(20deg);

•

perspective() sets the angle of the view
•

the higher the value the further you are away from the element

•

the lower the value the closer you are to the element

•

your will be using rotateY() and rotateX() the most

•

x,y,z
y-axis

x-axis
http://flisterz.com/foldcover/
http://codepen.io/s8770125/pen/gLrux
https://developer.mozilla.org/en-US/demos/detail/paperfold-css/launch
<div id="element" class="flipInY"></div>!
.flipInY!
{!
! -webkit-transform-origin: left bottom;!!
! -webkit-animation: flipInY 1s;! ! ! !
! -webkit-animation-fill-mode: forwards;!
}!
!

@-webkit-keyframes flipInY!
{!
! 0%
{ -webkit-transform: perspective(400px) rotateY( 90deg ); opacity: 0; }!
! 40%
{ -webkit-transform: perspective(400px) rotateY( -10deg ); }!
! 70%
{ -webkit-transform: perspective(400px) rotateY( 10deg ); }!
! 100%
{ -webkit-transform: perspective(400px) rotateY( 0deg ); opacity: 1; }!
}!
you will be creating animations
where you call a transform that
uses a translate function
Get to work: animation1
Get to work: animation2
pitfalls
web dev hell
browser support
•

do I need vendor prefixes?

•

fallbacks? jQuery’s .animate()?

•

transforms on older browsers: cssSandpaper

•

performance (especially on mobile)
•

test test test!

•

use transforms instead of top/left/margin
considerations
•

does the animation distract from the information it
should be supporting?

•

does your solution work on *any* device?

•

what’s the worst case scenario?
must read
•

http://www.sitepoint.com/advanced-css3-2d-and-3d-transformtechniques/

•

http://learn.shayhowe.com/advanced-html-css/css-transforms

•

http://learn.shayhowe.com/advanced-html-css/transitions-animations

•

http://css3.bradshawenterprises.com/transitions/

•

http://www.kirupa.com/html5/css3_animations_vs_transitions.htm

•

Bonus inspiration: http://uxrave.com/

Contenu connexe

Tendances

Tendances (20)

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
 
Canvas
CanvasCanvas
Canvas
 
PreDevCampSF - CSS3 Tricks
PreDevCampSF - CSS3 TricksPreDevCampSF - CSS3 Tricks
PreDevCampSF - CSS3 Tricks
 
CSS3 Implementable Features
CSS3 Implementable FeaturesCSS3 Implementable Features
CSS3 Implementable Features
 
CSS3 For WebKit: iPadDevCamp Presentation
CSS3 For WebKit: iPadDevCamp PresentationCSS3 For WebKit: iPadDevCamp Presentation
CSS3 For WebKit: iPadDevCamp Presentation
 
Svg
SvgSvg
Svg
 
Randomising css animations
Randomising css animationsRandomising css animations
Randomising css animations
 
Open Web Camp: CSS3 Implementable Features
Open Web Camp: CSS3 Implementable FeaturesOpen Web Camp: CSS3 Implementable Features
Open Web Camp: CSS3 Implementable Features
 
Web Development for Mobile: GTUG Talk at Google
Web Development for Mobile: GTUG Talk at GoogleWeb Development for Mobile: GTUG Talk at Google
Web Development for Mobile: GTUG Talk at Google
 
Css3
Css3Css3
Css3
 
Introduction to HTML5 Canvas
Introduction to HTML5 CanvasIntroduction to HTML5 Canvas
Introduction to HTML5 Canvas
 
Angular animate
Angular animateAngular animate
Angular animate
 
Html5 SVG
Html5 SVGHtml5 SVG
Html5 SVG
 
SVG - Scalable Vector Graphic
SVG - Scalable Vector GraphicSVG - Scalable Vector Graphic
SVG - Scalable Vector Graphic
 
HTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebHTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the Web
 
Douban pulse
Douban pulseDouban pulse
Douban pulse
 
Web Design Trends 2010 - What Is CSS3 All About?
Web Design Trends 2010 - What Is CSS3 All About?Web Design Trends 2010 - What Is CSS3 All About?
Web Design Trends 2010 - What Is CSS3 All About?
 
Html5
Html5Html5
Html5
 
HTML5 and CSS3 Shizzle
HTML5 and CSS3 ShizzleHTML5 and CSS3 Shizzle
HTML5 and CSS3 Shizzle
 
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile Event
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile EventHTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile Event
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile Event
 

Similaire à Mastering CSS Animations

CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)
창석 한
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive Graphics
Blazing Cloud
 

Similaire à Mastering CSS Animations (20)

Rich and Beautiful: Making Attractive Apps in HTML5 [Wpg 2013]
Rich and Beautiful: Making Attractive Apps in HTML5 [Wpg 2013]Rich and Beautiful: Making Attractive Apps in HTML5 [Wpg 2013]
Rich and Beautiful: Making Attractive Apps in HTML5 [Wpg 2013]
 
CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)
 
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
 
CSS and CSS3
CSS and CSS3CSS and CSS3
CSS and CSS3
 
Make your animations perform well
Make your animations perform wellMake your animations perform well
Make your animations perform well
 
Designing Your Next Generation Web Pages with CSS3
Designing Your Next Generation Web Pages with CSS3Designing Your Next Generation Web Pages with CSS3
Designing Your Next Generation Web Pages with CSS3
 
Make your animations perform well - Anna Migas - Codemotion Rome 2017
Make your animations perform well - Anna Migas - Codemotion Rome 2017Make your animations perform well - Anna Migas - Codemotion Rome 2017
Make your animations perform well - Anna Migas - Codemotion Rome 2017
 
Iagc2
Iagc2Iagc2
Iagc2
 
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
 
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
 
Making Links Magical Again with CSS
Making Links Magical Again with CSSMaking Links Magical Again with CSS
Making Links Magical Again with CSS
 
The web standards gentleman: a matter of (evolving) standards)
The web standards gentleman: a matter of (evolving) standards)The web standards gentleman: a matter of (evolving) standards)
The web standards gentleman: a matter of (evolving) standards)
 
Before Going Vector
Before Going VectorBefore Going Vector
Before Going Vector
 
CSS3: Are you experienced?
CSS3: Are you experienced?CSS3: Are you experienced?
CSS3: Are you experienced?
 
MTA managing the graphical interface by using css
MTA managing the graphical interface by using cssMTA managing the graphical interface by using css
MTA managing the graphical interface by using css
 
The Future of HTML Motion Design
The Future of HTML Motion DesignThe Future of HTML Motion Design
The Future of HTML Motion Design
 
Trendsetting: Web Design and Beyond
Trendsetting: Web Design and BeyondTrendsetting: Web Design and Beyond
Trendsetting: Web Design and Beyond
 
Sachin Foujdar , BCA Third Year
Sachin Foujdar , BCA Third YearSachin Foujdar , BCA Third Year
Sachin Foujdar , BCA Third Year
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive Graphics
 
SVG, CSS3, and D3 for Beginners
SVG, CSS3, and D3 for BeginnersSVG, CSS3, and D3 for Beginners
SVG, CSS3, and D3 for Beginners
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

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
 
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...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Mastering CSS Animations