AngularJS-之-angular-animate.js使用篇(ngAnimate)

How to use AngularJS with NgAnimate

The directive nganimate is very simple. You just need to declare the ng-animate attribute to an element that have another directive that changes the DOM.

You can use the animations with the directives:

DirectiveAnimation Type
ngRepeatenter, leave and move
ngViewenter and leave
ngIncludeenter and leave
ngSwitchenter and leave
ngIfenter and leave
ngShow and ngHideshow and hide

And there are three ways to make animations in AngularJS:

  • CSS3 Transitions
  • CSS3 Animations
  • Javascript

I think that the CSS3 Transitions is the easiest way to do animation, but with the CSS3 Animations you can do much more complex animations. And with javascript, it is possible to do dynamic animations.

We will provite plunkers sample for a lot of cases, than you just need to change the css file to change the animation.

Important

You need to use at least the AngularJS 1.1.5.
//ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js

CSS Class Names

By default, ngAnimate attaches two CSS classes for each animation event to the DOM element to achieve the animation. One with the animation name plus the animation type, and then, other with the animation nameplus the animation type plus the sufix "active".

For example, if you have an animation named animate, during the ngRepeat enter phase, the Angular will attach the class "animate-enter" and them the class "animate-enter-active".

There are 2 ways to set the name of the CSS3 classes that the directive will use, the short hand way, that you just set the animation name, or you can set an object that you will set the class for each animation type for the directive.

Sample

  1. <!-- Short Hand -->
  2. <div ng-repeat="item in itens" ng-animate=" 'animate' ">
  3. ...
  4. </div>
  5.  
  6. <!-- Expanded -->
  7. <div ng-repeat="item in itens" ng-animate="{enter: 'animate-enter', leave: 'animate-leave'}">
  8. ...
  9. </div>

In both cases, the classes will be:

  • For Enter: animate-enter & animate-enter-active
  • For Leave: animate-leave & animate-leave-active
CSS Transition

To define a class with a CSS3 Transition, first set the transition property and the initial element state at thesetup class. Then, just set the final state at the active class.

For example, if you want the fade animation, set opacity to 0 at the setup class, and opacity to 1 at the active, like in this sample:

  1. .animate-enter {
  2. -webkit-transition: 1s linear all; /* Chrome */
  3. transition: 1s linear all;
  4. opacity: 0;
  5. }
  6.  
  7. .animate-enter.animate-enter-active {
  8. opacity: 1;
  9. }

Be careful, and always use the animate-enter-active class with the animate-enter class, like the sample.

Contribute

Fell free to use and change any sample at this page. If you have any new animation ideas, please, send me the plunker and I will input it at this site.

Ng Repeat Animation

This is the most useful tag. Below you can see an HTML sample, and you can edit it at plunker. To test new css structures, just change de style.css file.

更多实例可参考:http://www.nganimate.org/

转载于:https://www.cnblogs.com/liangliangjiang/p/6650949.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值