+ All Categories
Home > Software > Demystifying Angular Animations

Demystifying Angular Animations

Date post: 28-Jan-2018
Category:
Upload: gil-fink
View: 215 times
Download: 0 times
Share this document with a friend
31
Demystifying Angular Animations Gil Fink CEO and Senior Consultant, sparXys
Transcript
Page 1: Demystifying Angular Animations

Demystifying Angular Animations

Gil Fink

CEO and Senior Consultant, sparXys

Page 2: Demystifying Angular Animations

Why to bother with animations?

Page 3: Demystifying Angular Animations

Better user experience (UX)

Page 4: Demystifying Angular Animations

Indicating that something happening/happened

Page 5: Demystifying Angular Animations

Just because we want a cool and shiny website!

Page 6: Demystifying Angular Animations

But… Web animation is HARD!

Page 7: Demystifying Angular Animations

About Me

• sparXys CEO and senior consultant

• Microsoft MVP in the last 8 years

• Pro Single Page Application Development (Apress) co-author

• 4 Microsoft Official Courses (MOCs) co-author

• GDG Rishon and AngularUP co-organizer

Page 8: Demystifying Angular Animations

Agenda

• Web animation

• Building our own Angular animation implementation

• Angular animation in a nutshell

Page 9: Demystifying Angular Animations

Web Animation Options

• Use JavaScript animation library

• Use CSS3 modules• CSS3 Animations

• CSS3 2D and 3D Transform

• CSS3 Transitions

Page 10: Demystifying Angular Animations

Welcome Web Animation API

Page 11: Demystifying Angular Animations

Web Animation API

• Enables you to hook into the browser’s animation engine

• Implemented on top of CSS3 animation and transitions

• Enables the ability to change animations during runtime

Page 12: Demystifying Angular Animations

Web Animation API in a Nutshell

• Use the new animate function • Pass Keyframes array and AnimationEffectTimingProperties object

document.getElementById("myPic").animate([

{transform: 'translate3D(0%, 0%, 0)', backgroundColor: '#000'},{transform: 'translate3D(10%, 10%, 0)', backgroundColor: '#ff0000'},{ transform: 'translate3D(0%, 0%, 0)', backgroundColor: '#000' }

], {duration: 3000,iterations: Infinity

});

Page 13: Demystifying Angular Animations

Web Animation APIDemo

Page 14: Demystifying Angular Animations

Web Animation API Support

Taken from “Can I Use…” website

• Use polyfill –https://github.com/web-animations/web-animations-js

Page 15: Demystifying Angular Animations

How can we use Web Animation API with Angular?

Page 16: Demystifying Angular Animations

Building our own Angular animation decoratorDemo

Page 17: Demystifying Angular Animations
Page 18: Demystifying Angular Animations
Page 19: Demystifying Angular Animations

@angular/animations

• Based on Web Animation API

• Animations are separated from Angular core

• Totally refactored

• Fully dynamic

Page 20: Demystifying Angular Animations

Angular Animation Module Setup

• Import the BrowserAnimationsModule to your ngModule

import {BrowserAnimationsModule} from "@angular/platform-browser/animations";

@NgModule({imports: [BrowserAnimationsModule]})

Page 21: Demystifying Angular Animations

How to Use Animation?

• Create animation trigger in the component template

• Describe the trigger in the component decorator

<div [@fade]="active ? 'in' : 'out'">hello there</div>

import {trigger, ...} from '@angular/animatons';

@Component({

animations: [trigger('fade', [ /*...*/ ])]

})

Page 22: Demystifying Angular Animations

How to Use Animation? – Cont.

• In the trigger you set • Transitions

• States

trigger('fadeIn', [

transition('out => in', [ style({ opacity: 0 }), animate(1000, style({ opacity: 1 })) ])

])

Page 23: Demystifying Angular Animations

Basic Angular Animation DemystifiedDemo

Page 24: Demystifying Angular Animations

States and Transitions

• Named states define styling of an element in state

• Transitions defines what happens when we move from one state to another (use =>)

state('state name', style({…}))

transition('* => in', [ style({…}), animate(1000, style({…})) ])

Page 25: Demystifying Angular Animations

Working with keyframes

• keyframes enables the creation of intricate animation

• Defined using the keyframes function and keyframe array

transition('void => *', [

animate(300, keyframes([

style({…, offset: 0}),

style({…, offset: 0.4}),

style({…, offset: 1.0})

]))

])

Page 26: Demystifying Angular Animations

Animation Groups

• Run animations in parallel using grouping

• Use the group function

transition('void => *', [

style({…}),

group([

animate('0.3s 0.1s ease', style({…})),

animate('0.3s ease', style({…}))

])

])

Page 27: Demystifying Angular Animations

Animation Callbacks

• You can wire to animation start and end callbacks

• Use the trigger start and done handlers

<li *ngFor="…"

(@fade.start)="animationStarted($event)"

(@fade.done)="animationDone($event)"

[@fade]="'in'">

</li>

Page 28: Demystifying Angular Animations

Adding Angular Animation to an AppDemo

Page 29: Demystifying Angular Animations

Summary

• Embrace the new Web Animation API

• Decorate components with animation in Angular apps

• Make your users happy!

Page 30: Demystifying Angular Animations

Resources

• Animations in Angular website - http://bit.ly/2ppuxsM

• ng-conf Animation video - http://bit.ly/2pSbhqe

• My Website – http://www.gilfink.net

• Follow me on Twitter – @gilfink

Page 31: Demystifying Angular Animations

Thank You!


Recommended