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
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
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’);
}
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
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;
}
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