fastest css3 animations

40
FASTEST CSS3 ANIMATIONS Berkay Beyaz - @berkaybeyaz6

Upload: berkaybeyaz

Post on 22-Jan-2018

66 views

Category:

Internet


2 download

TRANSCRIPT

Page 1: Fastest css3 animations

FASTEST CSS3 ANIMATIONS

Berkay Beyaz - @berkaybeyaz6

Page 2: Fastest css3 animations

WHO AM I ?

• At 17• Entrepreneur @Splashup - http://splashup.in• Backend Developer

Page 3: Fastest css3 animations

WHY ANIMATE ?

• Delightful user experience• Hiding possible loading times• For attract attention

Page 4: Fastest css3 animations

SCROLLING

UNPLEASANT UX DELIGHTFUL UX

Page 5: Fastest css3 animations

jQuery way

Page 6: Fastest css3 animations

400px

Page 7: Fastest css3 animations

CSS

.Component {width: 100px;height: 100px;background: red;position: absolute;top: 0;left: 0;

}

HTM

L

<div class=“Component”></div>

JS

$(“.Component”).animate({left: 400}, {duration: 200});

Page 8: Fastest css3 animations

HOW IT WORKS ANIMATE ON JQUERY ?

Css3 fallback requestAnimationFrame()

setInterval()

Dom Manipulation

Page 9: Fastest css3 animations

T H AT ' S A L L R I G H T ?

Page 10: Fastest css3 animations

NOT LIKE THAT

Page 11: Fastest css3 animations

W H AT W E D O N O W ?

Page 12: Fastest css3 animations
Page 13: Fastest css3 animations

VELOCITY.JS• Velocity is an animation engine

• jQuery, it uses its own animation stack that delivers its performance through two

underlying principles

• It works with and without jQuery. It’s faster than jQuery

jQuery

jQuery animation partials.

Velocity.js

Page 14: Fastest css3 animations
Page 15: Fastest css3 animations

VELOCITY SCHEME

Sync. DOM tween stack to

minimize Layout Trashing

(Recalculate Style)

cache values to minimize DOM

querying

Page 16: Fastest css3 animations
Page 17: Fastest css3 animations

BROWSER SUPPORT

Page 18: Fastest css3 animations

PROGRESSIVE ENHANCEMENT

Old Browsers

+ Basic functionality- UI transitions

Old Browsers

+ Basic functionality+ UI transitions

Page 19: Fastest css3 animations

TESTING ON BROWSERS

RESULTS

Page 20: Fastest css3 animations

S O L U T I O N ?

Page 21: Fastest css3 animations

AUTOPREFIXER• Add the desired vendor prefixes and remove unnecessary in your CSS

• Violates D.R.Y. principle

• Compatible with all browsers

• Using with Grunt

http://bitly.com/2ejNcjs

Page 22: Fastest css3 animations

AUTOPREFIXER

.myComponent {transform: translateX(0);

}

.myComponent{-webkit-transform: translateX(0);-ms-transform: translateX(0);transform: translateX(0);

}

CSS

GEN

ERAT

ED C

SS

Tutorial : http://bit.ly/1SWtDdz

Page 23: Fastest css3 animations

Basic Animations

Page 24: Fastest css3 animations

1. CSS3 TRANSITIONSC

SS

.Component {width: 100px;height: 100px;background: red;-webkit-transition: width 2s; transition: width 2s;

}

.Component:hover {width: 300px;

}

Page 25: Fastest css3 animations

2. CSS3 Transforms

Page 26: Fastest css3 animations

CSS3 TRANSFORMS

Rotate Scale Translate

Allow us to visually manipulate elements (2D & 3D)

Page 27: Fastest css3 animations

IDENTIFYING THE BOTTLENECK

TOP/LEFT

• Might affect the layout

• Recalculates style

TRANSLATE

• Does not affect the

element’s neighbors

• Does not recalculate style

Suitable for layout Suitable for animations

Page 28: Fastest css3 animations

EXAMPLE CODE

#box{transition: 200ms;

}

.animate-it{

}

CSS

transform: translateX(400px);left: 400px;

lefttransform

Page 29: Fastest css3 animations

3. HARDWARE ACCELERATION

Page 30: Fastest css3 animations

HOW IT WORKS ?

Compute - IntensiveFunctions Sequential

CPU Code

MULTIPLECORES

HUNDREDSOF CORES

APPLICATION CODE

GPU

Page 31: Fastest css3 animations

COMPUTE INTENSIVE FUNCTIONS

• 3D animations: translate3d(5px, 5px, 5px);

• What about 2D animations?

• translateX(400px) == translate3d(400px, 0, 0)

• transform: translateX(400px) translateZ(0);

Page 32: Fastest css3 animations

FORCING HARDWARE ACCELERATION

#box{transition: transform 200ms;

}

.animate-it{transform:

}

CSS

translateX(400px);translate3d(400px, 0, 0);

Page 33: Fastest css3 animations

4 THINGS A BROWSER CAN ANIMATE CHEAPLY

Position : transform: translate(x, y)

Scale :

Rotation :

Opacity :

transform: scale(n)

transform: rotate(deg)

opacity: 0...1

Page 34: Fastest css3 animations

P R O F I L I N G

Page 35: Fastest css3 animations

PROFILING

• Computer display refresh rate: 60Hz

• At 60hz: 16ms to prepare for the next frame

• Chrome Dev tools: Timeline

• Identify possible bottlenecks

• Lag begins to show at: 30Hz

Page 36: Fastest css3 animations

CONSEQUENTLY

Web Animation Translate/Scale 300 Dots – 98.9FPS

jQuery 3 Animation 300 Dots – 21.5FPS

https://www.greensock.com/js/speed.html

Page 37: Fastest css3 animations

C H O O S E I T !

Page 38: Fastest css3 animations

BRIEF

• Don’t animate using jQuery

• Use autoprefixer or a similar tool

• Use Top & Left for the layout only

• Move elements using translateX & translateY

• Use hardware acceleration (responsibly)

• Don’t Guess It, Profile It!

• Make CSS3 transitions part of your coding habits

Page 39: Fastest css3 animations

THANK YOU

@berkaybeyaz1

@berkaybeyaz6

.in

Page 40: Fastest css3 animations

QUESTIONS ?