AngularJS Animation

AngularJS Animations


AngularJS provides animated transitions, with help from CSS.

What is an Animation?

An animation is when the transformation of an HTML element gives you an illusion of motion.

Example:
Check the checkbox to hide the DIV:

<body ng-app="ngAnimate">

Hide the DIV: <input type="checkbox" ng-model="mycheck">

<div ng-hide="mycheck"></div>

</body>


What do I Need?


To make your applications ready for animations, you must include the AngularJS Animate library:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-animate.js"></script>

Then you must refer to the ngAnimate module in your application:

<body ng-app="ngAnimate">

Or if your application has a name, add ngAnimate as a dependency in your application module:

Example:

<body ng-app="myapp">

<h1>Hide the DIV: <input type="checkbox" ng-model="mycheck"></h1>

<div ng-hide="mycheck"></div>

<script>
var app = angular.module('myapp', ['ngAnimate']);
</script>


What Does ngAnimate Do?

The ngAnimate module adds and removes classes.

The ngAnimate module does not animate your HTML elements, but when ngAnimate notice certain events, like hide or show of an HTML element, the element gets some pre-defined classes which can be used to make animations.

The directives in AngularJS who add/remove classes are:

  • ng-show
  • ng-hide
  • ng-class
  • ng-view
  • ng-include
  • ng-repeat
  • ng-if
  • ng-switch


The ng-show and ng-hide directives add or remove an ng-hide class value.

The other directives add an ng-enter class value when they enter the DOM, and an ng-leave attribute when they are removed from the DOM.

The ng-repeat directive also adds an ng-move class value when the HTML element changes position.

In addition, during the animation, the HTML element will have a set of class values, which will be removed when the animation has finished. Example: the ng-hide directive will add these class values:

  • ng-animate
  • ng-hide-animate
  • ng-hide-add (if the element will be hidden)
  • ng-hide-remove (if the element will be showed)
  • ng-hide-add-active (if the element will be hidden)
  • ng-hide-remove-active (if the element will be showed)


Animations Using CSS

We can use CSS transitions or CSS animations to animate HTML elements.

CSS Transitions


CSS transitions allow you to change CSS property values smoothly, from one value to another, over a given duration:

Example:

When the DIV element gets the .ng-hide class, the transition will take 0.5 seconds, and the height will smoothly change from 100px to 0:

<style>
div {
  transition: all linear 0.5s;
  background-color: lightblue;
  height: 100px;
}

.ng-hide {
  height: 0;
}
</style>

 CSS Animations


CSS Animations allows you to change CSS property values smoothly, from one value to another, over a given duration:

Example:

When the DIV element gets the .ng-hide class, the myChange animation will run, which will smoothly change the height from 100px to 0:

<style>
@keyframes myChange {
  from {
    height: 100px;
  } to {
    height: 0;
  }
}

div {
  height: 100px;
  background-color: lightblue;
}

div.ng-hide {
  animation: 0.5s myChange;
}
</style>

Note: Applications should not be filled with animations, but some animations can make the application easier to understand.

Post a Comment

1 Comments

  1. Come to the 【 Netfix Movie 】 Web Site. Watch Netfix Movie TV Shows Online Streaming or Downloading New Movie 4K ULTRAHD FULL HD (1080p) Enjoy this size Your devise Smart Phone, Smart TV, Game Console, PC,Leptop, Mac, Mobile, Tablet And More Start Your Free Trial . Click Here to link 【 Netfix Movie 】.


    Coming soon, see the new movie Click here to know more about the links below....

    Avengers 4
    Click Here ► Avengers 4 Full Movie Download

    Godzilla: King of the Monsters
    Click Here ► Godzilla: King of the Monsters Full Movie Download

    Dark Phoenix
    Click Here ► Dark Phoenix Full Movie Download

    Spider-Man: Far From Home
    Click Here ► Spider-Man: Far From Home Full Movie Download

    Hobbs & Shaw
    Click Here ► Hobbs & Shaw Full Movie Download

    Angry Birds 2
    Click Here ► Angry Birds 2 Full Movie Download

    Frozen 2
    Click Here ► Frozen 2 Full Movie Download

    Star Wars: Episode IX
    Click Here ► Star Wars: Episode IX Full Movie Download

    ReplyDelete