Angular-animation ., Angular-Animation

Source: Internet
Author: User

Angular-animation ., Angular-Animation
What is the ngAnimate plug-in?

The ngAnimate plug-in provides animations for elements like its name.

How to define an animation?

The first step must be to introduce the plug-in

<script src="//cdn.bootcss.com/angular.js/1.3.20/angular.js"></script><script src="//cdn.bootcss.com/angular.js/1.3.20/angular-animate.min.js"></script>

 

Step 2 let the app introduce (dependency) This plug-in

 
Var appH5 = angular. module ("app", ['nganimate']); appH5.controller ("myTabCtrl", ['$ scope', function ($ scope) {$ scope. isShow = true;}]) <body ng-controller = "myTabCtrl"> <input type = "checkbox" ng-model = "isShow"/> <div class = "new-item" ng-if =" isShow "> I am the element to be animated </div> </body> the first way to add an animation: sample style definition using css3.0. new-item {padding: 10px; border-bottom: 1px solid # ededed; font-size: 1.5rem; position: relative; transition: all 0.5 s ;} /* The element enters the initial state of the page */. new-item.ng-enter {top: 10px;}/* final state after entering the page animation */. new-item.ng-enter-active {top: 0px;}/* element removal page initial state */. new-item.ng-leave {opacity: 1;}/* final state after removing the page animation */. new-item.ng-leave-active {opacity: 0;} // html <div class = "new-item"> I am the element to be animated </div>
 

 

 
  • Why can an animation be generated when a style is added?
    When an element enters the page, angular will add class ng-enter and ng-enter-active to the element in sequence. As we all know, after an element defines transition, CSS3.0, when the attribute values of the two identical attributes change, the transition animation is used to change the attribute values. The same is true when an element is removed from a page. Therefore, we only need to define the four classes of the element to define the States of these four time points. The rest will be done by angular.
  • Which commands Support Animation definition in this way?
    Ng-if, ng-view, ng-repeat, ng-include, ng-switch
    These commands display and hide elements by creating and removing nodes.
  • Difference Between ng-repeat
    . New-item {padding: 10px; border-bottom: 1px solid # ededed; font-size: 1.5rem; position: relative; transition: all 0.5 s ;}. new-item.ng-enter {top: 10px ;}. new-item.ng-enter-active {top: 0px ;}. the new-item.ng-enter-stagger {/* ng-repeat provides this style to execute an animation in sequence for each item entry */animation-delay: 100 ms;-webkit-animation-delay: 100 ms ;}. new-item.ng-leave {opacity: 1 ;}. new-item.ng-leave-active {opacity: 1 ;}. new-item.ng-leave-stagger {animation-delay: 100 ms;-webkit-animation-delay: 100 ms ;} // html <div class = "new-item" ng-repeat = "new in news" >{{ new. title }}</div>

     

Just now, commands implemented by creating and deleting elements can be animated, so they only need to change the style display or hide the elements (ng-show ng-hide ng-class) can it be animated?

 

  
/* Hide the initial state of an element */. new-item.ng-hide-add {opacity: 1;}/* Hide the final state after the operation animation */. new-item.ng-hide-add-active {opacity: 0;}/* element displays initial state */. new-item.ng-hide-remove {top: 10px;}/* displays the final state after the action animation */. new-item.ng-hide-remove-active {top: 0px ;}

 

 

The second way to add an animation: Through js

// Ng-if, ng-view, ng-repeat, ng-include, and ng-switch commands appH5.animation (". new-item ", function () {return {leave: function (element, done) {// The first parameter is the moving element, and the second parameter is the callback after the animation is completed, it must be called. If it is not called, the command function will not execute $ (element ). animate ({width: 0, height: 0}, 1000, done); // use jQuery}, enter: function (element, done) {detail (element).css ({width: 100, height: 100}); // use jQuery $ (element ). animate ({width: 100, height: 100}, 1000, done) // use jQuery }}}); // ng-show ng-hide ng-class command appH5.animation (". new-item ", function () {return {addClass: function (element, sClass, done) {// The first parameter is the moving element // The second parameter is the element style --> generally, it is not used. // The third parameter is the callback after the animation is completed and must be called, if the command is not called, $ (element) is not executed ). animate ({width: 0, height: 0}, 1000, done)}, removeClass: function (element, sClass, done) {detail (element).css ({width: 100, height: 100}); $ (element ). animate ({width: 100, height: 100}, 1000, done )}}});

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.