css transitions, transforms, animations

34
HUGE / CSS Transforms, Transitions, & Animations 1 CSS Transitions, Transforms & Animations Tuesday February 23, 2011

Upload: rob-laplaca

Post on 10-May-2015

5.013 views

Category:

Technology


0 download

DESCRIPTION

Feb 23rd presentation at the meetup at @hugeinc. http://www.meetup.com/doctype-html/

TRANSCRIPT

Page 1: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 1

CSS Transitions, Transforms & AnimationsTuesday February 23, 2011

Page 2: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 2

transitions

Page 3: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 3

Ch-ch-ch-ch-changes

Class .a

Class .b

arrow === css3 transition == ZOMG

Page 4: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 4

What (are CSS3 transitions)?

Sometimes we change CSS properties dynamically bychanging or adding a class. e.g. $(‘input’).addClass(‘error’);

CSS3 Transitions allow us to animate the change in these CSS properties… easily!

Page 5: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 5

Transitions defined & browser support

-browser-transition: {property} {duration} {easing} {delay};

easing defaults: linear, ease-in, ease-out, ease-in-out

-webkit-transition: (Safari 3.1+, Chrome since forever)-moz-transition: (FF 4+)-o-transition: (Opera 10.doYouCare) -msie-transition: (apparently NOT ie9 )

Page 6: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 6

animations

Page 7: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 7

7

keyframes

changing multiple styles at different times over an interval

from {left: 100px;width: 100px;height: 100px;animation-timing: ease-in;}

to {left: 200px;width: 50px;height: 50px;}

but what’s going on in the middle?

Page 8: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 8

8

keyframes (cont.)

from {...}

30% {left: 200px;width: 50px;height: 50px;}

to {transform: rotate(180deg);left: 200px;}

60% {left: 100px;}

Page 9: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 9

9

using animations programmatically

Initializer• initAnimationEvent - Initializes an animation event given a

DOMobject• typeArg (string)• canBubbleArg (boolean)• cancelableArg (boolean)• animationNameArg (string)• elapsedTimeArg (float)

Callbacks• animationStart• animationEnd• animationIteration

Page 10: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 10

10

optionsanimation-delay: 5s;

• delay to startanimation-direction: alternate;

• animation is played in reverse on odd iterationsanimation-durations: 5s;

• time to complete animationanimation-iteration-count: 5;

• times to play animation (doubled for alternate)animation-name: myAnimation;

• unique ID for animationanimation-play-state: paused;

• pauses/plays the animationanimation-timing-function: cubic-bezier(x1,y1,x2,y2)

• a custom/predefined timing curve to follow

Page 11: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 11

11

GPU vs. CPUhardware acceleration

It’s the difference between...

GPU’s are very good BitBLIT Operations

Page 12: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 12

12

into the mainstream

developers don’t want to code animations

Animation Builders

(Sencha Animator)

Banner Ads Purely Native Web Apps

Native-Like Interfaces Immersive Sites

Page 14: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 14

transforms

Page 15: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 15

transform: rotate(x)

rotate(45deg)

rotate(180deg)rotate(0deg)

Page 16: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 16

transform: scale(x)

scale(1)

scale(2)

Page 17: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 17

transform: translate(x, y)

translate(0,0)

translate(200px, 100px)

Page 18: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 18

transform: skew(x, y)

skew(0deg, 0deg) skewX(25deg) skewY(25deg)

Page 19: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 19

transform: skew(x, y)

skew(0deg, 0deg) skewX(25deg) skewY(25deg)

25°

25°

Page 20: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 20

transform: skew(x, y)

skew(0deg, 0deg) skew(25deg, 25deg)

Page 21: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 21

transform: matrix(a,b,c,d,e,f)

???

Page 22: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 22

transform: matrix(a,b,c,d,e,f)

matrix(a,b,c,d,e,f) =a c eb d f0 0 1

3x3 matrix

Page 23: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 23

transform: matrix(a,b,c,d,e,f)

matrix(1,0,0,1,0,0) =1 0 00 1 00 0 1

3x3 matrix

Page 24: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 24

transform: matrix(a,b,c,d,e,f)

matrix(2,0,0,2,0,0) =2 0 00 2 00 0 1

3x3 matrix

Page 25: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 25

transform: matrix(a,b,c,d,e,f)

matrix(2,0,0,2,0,0) = scale(2)

Page 26: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 26

transform: matrix(a,b,c,d,e,f)

scale translate

sx 0 00 sy 00 0 1

1 0 tx0 1 ty0 0 1

rotate

cos(a) -sin(a) 0sin(a) cos(a) 00 0 1

skew

1 tan(a) 0tan(a) 1 00 0 1

Page 27: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 27

transform: matrix(a,b,c,d,e,f)

flip horizontal

-1 0 00 1 00 0 1

flip vertical

1 0 00 -1 00 0 1

flip both

-1 0 00 -1 00 0 1

Page 28: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 28

transform-origin: x, y

transform-origin: 50% 50% transform-origin: top left

Page 29: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 29

Browser Support

-moz-transform: rotate(45deg); // FF3.5+-webkit-transform: rotate(45deg); // Saf3.1+, Chrome-o-transform: rotate(45deg); // Opera 10.5-ms-transform: rotate(45deg); // IE9transform: rotate(45deg);

filter: progid:DXImageTransform.Microsoft.Matrix( M11=0.7071067811865476, M12=-0.7071067811865476, M21=0.7071067811865476, M22=0.7071067811865476, sizingMethod='auto expand'); // IE6 – IE9

Page 30: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 30

3D Transformations

Page 31: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 31

What’s under the hood?

1 0 0 00 1 0 00 0 1 00 0 0 1

4x4 matrix

Page 32: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 32

3D functions

• rotate3d

• translate3d

• skew3d

• scale3d

• matrix3d

Page 33: CSS Transitions, Transforms, Animations

HUGE / CSS Transforms, Transitions, & Animations 33

Other properties

• transform-origin

• transform-style

• perspective

• perspective-origin

• backface-visibility