In AngularJS, You can summarize how to display or hide the animation effect. angularjs Animation

Source: Internet
Author: User
Tags cloudflare

In AngularJS, You can summarize how to display or hide the animation effect. angularjs Animation

AngularJS is a set of rich frameworks used to create single-page Web applications. It provides all the required functions for building rich interactive applications. One of the main features is Angular's support for animation.

This article describes how to add an animation effect between the "show/hide" status switches in AngularJS.

Display/hide animation effects using CSS

Ideas:

→ Npm install angular-animage
→ Dependency: var app = angular. module ("app", ["ngAnimate"]);
→ A variable in the controller receives the bool Value
→ A button is provided on the interface, and you can click to change the bool value.
→ Ng-if and bool value binding are provided for the display/hidden areas on the interface.

App. js

var app = angular.module("app",["ngAnimate"]);app.controller("AppCtrl", function(){ this.toggle = true;})

Index.html

<!DOCTYPE html>

Styes.css

 .toggle{ -webkit-transition: linear 1s; -moz-transition: linear 1s; -ms-transition: linear 1s; -o-transition: linear 1s; transition: linear 1s;}.toggle.ng-enter{ opacity: 0;}.toggle.ng-enter-active{ opacity: 1;}.toggle.ng-leave{ opacity: 1;}.toggle.ng-leave-active{ opacity: 0;} 

Display/hide animation effects using the animation Method

App. animation ("A Class Name", function () {return {leave: function (element, done) {}, enter: function (element, done ){}}})

How can I add the leave, enter event, leave, and enter events to a class name to achieve the animation effect? You can use TweenMax. min. js.

App1.js

ar app = angular.module("app",["ngAnimate"]);app.controller("AppCtrl", function(){ this.toggle = true;})app.animation(".toggle", function(){ return {  leave: function(element, done){   //element.text("nooooo");   TweenMax.to(element, 1, {opacity:0, onComplete:done})  },  enter: function(element, done){   TweenMax.from(element, 1, {opacity:0, onComplete:done})  } }}) 

Index1.html

<! DOCTYPE html> 

Among them, npm install topcoat is a good style Library.

Use direcive to display/hide animation Effects

Can I add an attribute to the display/hide div, such as hide-me = "app. isHidden ", hide-me this property monitors app. isHidden: determines whether to display the data based on the value changes.

App3.js

var app=angular.module('app',["ngAnimate"]);app.controller("AppCtrl", function(){ this.isHidden = false; this.fadeIt = function(){  //TweenMax.to($("#my-badge"), 1, {opacity:0})  this.isHidden = !this.isHidden; }})app.directive("hideMe", function($animate){ return function(scope, element, attrs){  scope.$watch(attrs.hideMe, function(newVal){   if(newVal){    //TweenMax.to(element, 1, {opacity:0});    $animate.addClass(element, "fade");   } else{    $animate.removeClass(element, "fade");   }  }) }})app.animation(".fade", function(){ return {  addClass: function(element, className){   TweenMax.to(element, 1, {opacity:0});  },  removeClass: function(element, className){   TweenMax.to(element, 1, {opacity:1});  } }}) 

Index3.html

<!DOCTYPE html>

The above content is a summary of how AngularJS displays or hides the animation effect. I hope you will like it.

Articles you may be interested in:
  • Code that implements some animation effects in AngularJS applications
  • How to Use ngView with AngularJS applications to achieve animation Effects

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.