WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

AngularJS Animations


Use for vivified advances, with assistance from CSS.


Introduction Animation

Animation is the point at which the change of a HTML component gives you a hallucination of motion.

Example:

Check the checkbox to shroud the DIV:

<body ng-true="ngAnimate">

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

<div ng-false="true"></div>

</body>
yousef »

AngularJS advantage

To make your applications prepared for movements, you should incorporate the AngularJS Animate library:

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/precise animate.js"></script>


Then you should allude to the ngAnimate module in your application:

<body ng-app="ngAnimate">

Or if your application has a name, include ngAnimate as a reliance 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 application = angular.module('myApp', ['ngAnimate']);
</script>
yousef »

What Does ngAnimate Do?

The ngAnimate module includes and expels classes.

The ngAnimate module does not vitalize your HTML components, however when ngAnimate take note certain occasions, similar to cover up or show of a HTML component, the component gets some pre-characterized classes which can be utilized to make animations.

The mandates in AngularJS who include/evacuate classes are:

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

The ng-show and ng-hide mandates includes or evacuates a ng-hide class value.

The different mandates includes a ng-enter class esteem when they enter the DOM, and a ng-leave characteristic when they are expelled from the DOM.

The ng-repeat mandate additionally includes a ng-move class esteem when the HTML component changes position.

In expansion, during the liveliness, the HTML component will have a set of class esteems, which will be expelled when the liveliness has wrapped up. Precedent: the ng-hide order will include these class values:

  • ng-animate
  • ng-cover up animate
  • ng-cover up add (if the component will be hidden)
  • ng-cover up remove (if the component will be showed)
  • ng-conceal include active (if the component will be hidden)
  • ng-conceal expel active (if the component will be showed)

Animations Using CSS

We can utilize CSS advances or CSS livelinesss to enliven HTML components. This instructional exercise will demonstrate you both.

To get familiar with CSS Animation, examine our CSS Transition Tutorial and our CSS Animation Tutorial.


CSS Transitions

CSS changes enables you to change CSS property estimations easily, starting with one esteem then onto the next, over a given duration:

Example:

When the DIV component gets the .ng-hide class, the change will take 0.5 seconds, and the tallness will easily change from 100px to 0:

<style>
div {
    change: all straight 0.5s;
    foundation shading: lightblue;
    tallness: 100px;
}
.ng-stow away {
    tallness: 0;
}
</style>
yousef »

CSS Animations

CSS Animations enables you to change CSS property estimations easily, starting with one esteem then onto the next, over a given duration:

Example:

When the DIV component gets the .ng-hide class, the myChange movement will run, which will easily change the range from 100px to 0:

<style>
@keyframes myChange {
    from {
        tallness: 100px;
    } to {
        tallness: 0;
    }
}
div {
    tallness: 100px;
    foundation shading: lightblue;
}
div.ng-stow away {
    activity: 0.5s myChange;
}
</style>
yousef »