Slide 1

Slide 1 text

Hello, the mixin!

Slide 2

Slide 2 text

Designing CSS Transitions Using AngularJS AN INTRODUCTION TO

Slide 3

Slide 3 text

UI logic ! polish & refinement

Slide 4

Slide 4 text

WHY I LIKE USING ANGULARJS TO PROTOTYPE INTERACTIONS

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Add or remove servers

Slide 7

Slide 7 text

... stuff ...
Add or remove servers

Slide 8

Slide 8 text

$( "#target" ).click(function() { $( "#another-target" ).addClass( "expanded" ); }); JavaScript
... stuff ...
Add or remove servers

Slide 9

Slide 9 text

Write less JavaScript ! ikr?!

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Add or remove servers

Slide 12

Slide 12 text

... stuff ...
Add or remove servers

Slide 13

Slide 13 text

Use features built into AngularJS to animate the transitions on the screen.

Slide 14

Slide 14 text

ng-if ! ng-show, ng-hide ! ng-model ! ng-pluralize ANGULAR FEATURES

Slide 15

Slide 15 text

I’m Jessica EX-PRODUCT DESIGNER AT

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

I LIKE USING A SANDBOX TO DESIGN CSS TRANSITIONS

Slide 18

Slide 18 text

Easier to share. ! Straight to the component. ! Easier to isolate bugs. SANDBOX PROS

Slide 19

Slide 19 text

Set up a AngularJS sandbox to design a component. I’ll use Plunker Plnkr.co I’LL DEMONSTRATE

Slide 20

Slide 20 text

From plnkr.co click “Editor” SETTING UP A SANDBOX Use a template in the drop down tinyurl.com/angular-animate

Slide 21

Slide 21 text

ADD ANGULAR-ANIMATE Now Angular’s prefab CSS classes are available to use in CSS transitions.

Slide 22

Slide 22 text

SWITCH FROM .CSS to .SCSS “New file”

Slide 23

Slide 23 text

SWITCH FROM .CSS to .SCSS Delete style.css Plunker watches & compiles your .scss/.sass extensions

Slide 24

Slide 24 text

Define ng-app & ng-controller in the HTML & ! Add ngAnimate & define the controller in app.js var app = angular.module('plunker', ["ngAnimate"]); ! app.controller('MainCtrl', function($scope) {}); HOOKING UP THE ANGULAR ISH Details on what this stuff does is on the AngularJS homepage angularjs.org

Slide 25

Slide 25 text

Fork this existing setup where it’s hooked up already: ! tinyurl.com/angular-animate

Slide 26

Slide 26 text

Here’s a cat!
CONDITIONALLY DISPLAY DOM ELEMENTS WITH ng-if This DIV would only be rendered if “showCat” evaluated to “true”

Slide 27

Slide 27 text

show the cat TOGGLE TRUE/FALSE WITH ng-click hide the cat

Slide 28

Slide 28 text

Hint: Watch a variable in the UI by putting it in double curly braces:

showCat is: {{ showCat }}.

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

NOW THE BASIC SHOW & HIDE BEHAVIORS ARE SET UP. ! LET’S ADD SOME ANIMATION USING CSS TRANSITIONS.

Slide 32

Slide 32 text

Here’s a cat!
WHEN ng-if BECOMES TRUE FALSE TRUE

Slide 33

Slide 33 text

Here’s a cat!
WHEN ng-if BECOMES TRUE FALSE TRUE .ng-enter

Slide 34

Slide 34 text

Here’s a cat!
WHEN ng-if BECOMES TRUE FALSE TRUE .ng-enter .ng-enter .ng-enter-active

Slide 35

Slide 35 text

Here’s a cat!
WHEN ng-if BECOMES TRUE FALSE TRUE .ng-enter .ng-enter .ng-enter-active *poof*

Slide 36

Slide 36 text

// the "ng-if true" transition starting point .cat.ng-enter { transition: 0.5s ease all; left: -300px; opacity: 0; } ! // the "ng-if true" transition ending point .cat.ng-enter.ng-enter-active { left: 0px; opacity:1; }

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

TRUE FALSE WHEN ng-if BECOMES FALSE
Here’s a cat!

Slide 40

Slide 40 text

TRUE FALSE .ng-leave WHEN ng-if BECOMES FALSE
Here’s a cat!

Slide 41

Slide 41 text

TRUE FALSE .ng-leave .ng-leave .ng-leave-active WHEN ng-if BECOMES FALSE
Here’s a cat!

Slide 42

Slide 42 text

TRUE FALSE .ng-leave .ng-leave .ng-leave-active *poof* WHEN ng-if BECOMES FALSE
Here’s a cat!

Slide 43

Slide 43 text

TRUE FALSE .ng-leave .ng-leave .ng-leave-active *poof* WHEN ng-if BECOMES FALSE
Here’s a cat!
(Also bye-bye DOM element)

Slide 44

Slide 44 text

// the "ng-if false" transition starting point .cat.ng-leave { -webkit-transition: 0.5s ease all; transition: 0.5s ease all; left: 0px; opacity: 1; } ! // the "ng-if false" transition ending point .cat.ng-leave.ng-leave-active { left: 700px; opacity: 0; }

Slide 45

Slide 45 text

CHEATSHEET ng-if CLASS WATERFALL FALSE ! ! TRUE ! ! FALSE .ng-enter .ng-enter.ng-enter-active *poof* (default styling) .ng-leave .ng-leave.ng-leave-active

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

CONDITIONALLY DISPLAY DOM ELEMENTS WITH ng-hide & ng-show

Slide 49

Slide 49 text

HOW ARE ng-hide & ng-show DIFFERENT FROM ng-if ng-if destroys the DOM element when it is false. ng-hide hides the DOM element with display: none !important; when true. ng-show hides the DOM element with display: none !important; when false.

Slide 50

Slide 50 text

HOW ARE ng-hide & ng-show DIFFERENT FROM ng-if ng-if Easiest to use the CSS transitions ng-hide & ng-show • None-destructive to the DOM • Trickier to use the CSS transitions

Slide 51

Slide 51 text

WHEN ng-show BECOMES TRUE
Here’s a panel!
This DIV would only be shown if “showPanel” evaluated to “true”

Slide 52

Slide 52 text

WHEN ng-show BECOMES TRUE FALSE ! ! ! ! ! TRUE

Slide 53

Slide 53 text

WHEN ng-show BECOMES TRUE FALSE ! ! ! ! ! TRUE .ng-hide

Slide 54

Slide 54 text

WHEN ng-show BECOMES TRUE FALSE ! ! ! ! ! TRUE .ng-hide Persistent class added to the DOM element when false.

Slide 55

Slide 55 text

WHEN ng-show BECOMES TRUE FALSE ! ! ! ! ! TRUE .ng-hide.ng-hide-remove .ng-hide Persistent class added to the DOM element when false.

Slide 56

Slide 56 text

WHEN ng-show BECOMES TRUE FALSE ! ! ! ! ! TRUE .ng-hide.ng-hide-remove .ng-hide-remove .ng-hide Persistent class added to the DOM element when false.

Slide 57

Slide 57 text

WHEN ng-show BECOMES TRUE FALSE ! ! ! ! ! TRUE .ng-hide.ng-hide-remove .ng-hide-remove *poof* .ng-hide Persistent class added to the DOM element when false.

Slide 58

Slide 58 text

WHEN ng-show BECOMES FALSE TRUE ! ! ! ! ! FALSE

Slide 59

Slide 59 text

WHEN ng-show BECOMES FALSE TRUE ! ! ! ! ! FALSE *No special classes are added*

Slide 60

Slide 60 text

WHEN ng-show BECOMES FALSE TRUE ! ! ! ! ! FALSE .ng-hide-add *No special classes are added*

Slide 61

Slide 61 text

WHEN ng-show BECOMES FALSE TRUE ! ! ! ! ! FALSE .ng-hide-add.ng-hide .ng-hide-add *No special classes are added*

Slide 62

Slide 62 text

WHEN ng-show BECOMES FALSE TRUE ! ! ! ! ! FALSE .ng-hide-add.ng-hide .ng-hide-add .ng-hide *No special classes are added*

Slide 63

Slide 63 text

WHEN ng-show BECOMES FALSE TRUE ! ! ! ! ! FALSE .ng-hide-add.ng-hide .ng-hide-add .ng-hide Persistent class added to the DOM element. *No special classes are added*

Slide 64

Slide 64 text

CHEATSHEET ng-show CLASS WATERFALL FALSE ! ! TRUE ! ! FALSE *poof* (default styling) .ng-hide.ng-hide-remove .ng-hide-remove .ng-hide .ng-hide-add.ng-hide .ng-hide-add .ng-hide

Slide 65

Slide 65 text

THE THING ABOUT .ng-hide

Slide 66

Slide 66 text

.ng-hide { display: none !important; } ANIMATION KILLER!

Slide 67

Slide 67 text

.ng-hide.ng-hide-add, .ng-hide.ng-hide-remove { display: block !important; } ANIMATION FIXER

Slide 68

Slide 68 text

BUTTON TO TOGGLE showPanel Toggle the panel

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

.nav ng-click="showPanel=!showPanel"

Slide 72

Slide 72 text

ng-show="showPanel" .panel .nav ng-click="showPanel=!showPanel"

Slide 73

Slide 73 text

// Default panel style .panel{ width: 400px; position: fixed; top: 0; bottom: 0; left: 200px; background: grey; } ! // Slide out transition for ng-show .panel.ng-hide { left: -400px; } ! .panel.ng-hide-remove, .panel.ng-hide-add { transition: .3s ease all; // overwrite .ng-hide’s default // of “display: none !important;” display: block !important; }

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

The slide-out Plunker ! tinyurl.com/slide-out-animation

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

MOCKING UP A FORM WITH ng-show + ng-pluralize ! BONUS: Reusing an animation

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

ng-click="scalingActionChosen='true'"

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

ng-show="scalingActionChosen"

Slide 84

Slide 84 text

ng-show="scalingActionChosen" class=”drop-in ng-hide”

Slide 85

Slide 85 text

/* Animation for showing the .scaling-action section */ .drop-in { transition: .3s linear all; opacity: 1; margin-top: 0px; } ! .drop-in.ng-hide { opacity: 0; margin-top: -15px; } ! .drop-in.ng-hide-add, .drop-in.ng-hide-remove { /* this needs to be here to make it visible during the animation */ display: block !important; }

Slide 86

Slide 86 text

The .drop-in class can now be applied to other elements with ng-hide or ng-show

Slide 87

Slide 87 text

I used it 4 times in this form.

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

ng-pluralize

Slide 91

Slide 91 text

!

Slide 92

Slide 92 text

!

Slide 93

Slide 93 text

Remastered Animation in AngularJS 1.2 ! by Year of Moo ! www.yearofmoo.com/2013/08/ remastered-animation-in- angularjs-1-2.html MORE IN DEPTH ARTICLE

Slide 94

Slide 94 text

Thanks! @jessicaspacekat