星空网 > 软件开发 > Java

[AngularJS] AngularJS系列 中级篇之动画

目录

  • CSS定义
  • JS定义

 

ng动画实际帮我们在状态切换的时候 添加特定的样式 从而实现动画效果.

一般我们会通过C3来实现具体的动画.

 

CSS定义

ng-if

图(实际上,图并不能展现出什么):

[AngularJS] AngularJS系列 中级篇之动画

 

 

HTML

<body ng-app="myApp">  <button ng-click="show=!show">Toggle</button>  <div ng-if="show" >Look Me</div>  <script type="text/javascript">    angular.module('myApp', ['ngAnimate'])  </script></body>

 

CSS

    .fade {      transition: 1s linear all;    }      .fade.ng-enter {        opacity: 0;      }        .fade.ng-enter.ng-enter-active {          opacity: 1;        }      .fade.ng-leave {        opacity: 1;      }        .fade.ng-leave.ng-leave-active {          opacity: 0;        }

 

enter和leave的执行过程:

[AngularJS] AngularJS系列 中级篇之动画

在元素创建的时候,会依次加上.ng-enter、.ng-enter-active的class,然后恢复为默认的class

同样在销毁的时候,会依次加上.ng-leave、.ng-leave-active的class,然后恢复为默认。

 

ngClass

这里只截取关键代码

  <button ng-click="onOff=!onOff">Toggle</button>  <div ng- >    Highlight this box  </div>

CSS

   .highlight {      transition: 1s linear all;    }      .highlight.on-add {        background: red;      }      .highlight.on {        background: yellow;      }      .highlight.on-remove {        background: blue;      }

效果图:

[AngularJS] AngularJS系列 中级篇之动画

 

 

1.5.8支持的指令与动画样式:

DirectiveSupported Animations
{@link ng.directive:ngRepeat#animations ngRepeat}enter, leave and move
{@link ngRoute.directive:ngView#animations ngView}enter and leave
{@link ng.directive:ngInclude#animations ngInclude}enter and leave
{@link ng.directive:ngSwitch#animations ngSwitch}enter and leave
{@link ng.directive:ngIf#animations ngIf}enter and leave
{@link ng.directive:ngClass#animations ngClass}add and remove (the CSS class(es) present)
{@link ng.directive:ngShow#animations ngShow} & {@link ng.directive:ngHide#animations ngHide}add and remove (the ng-hide class value)
{@link ng.directive:form#animation-hooks form} & {@link ng.directive:ngModel#animation-hooks ngModel}add and remove (dirty, pristine, valid, invalid & all other validations)
{@link module:ngMessages#animations ngMessages}add and remove (ng-active & ng-inactive)
{@link module:ngMessages#animations ngMessage}enter and leave

 

 

JS定义

HTML

<body ng-app="myApp" ng-init="items=[1,2,3,4,5,6]">  <button ng-click="show=!show">Toggle</button>  <div ng-if="show" ng-repeat="item in items" >    {{ item }}  </div></body>

js操作

    angular.module('myApp', ['ngAnimate'])      .animation('.slide', [        function () {          return {            enter: function (element, doneFn) {              jQuery(element).fadeIn(1000, doneFn);            },            move: function (element, doneFn) {              jQuery(element).fadeIn(1000, doneFn);            },            leave: function (element, doneFn) {              jQuery(element).fadeOut(1000, doneFn);            }          }        }      ]);

其中的enter move leave 对应状态变化的事件,详情建议参考源码中的$$AnimateJsProvider.

 

本文地址:http://www.cnblogs.com/neverc/p/5924789.html




原标题:[AngularJS] AngularJS系列 中级篇之动画

关键词:JS

JS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

想要在黑五实现逆袭?你的Google购物广告做好准备了吗?:https://www.ikjzd.com/articles/132552
2020年美国大选对全球贸易跨境电商会有哪些影响?:https://www.ikjzd.com/articles/132553
速卖通沙特市场家用产品需求创纪录增长:https://www.ikjzd.com/articles/132555
DHL Express为“历史性”旺季做好准备:https://www.ikjzd.com/articles/132556
Shopee&Lazada“双十一”必爆选品TOP清单!直接进来抄作业!:https://www.ikjzd.com/articles/132557
FB+Youtube营销才是中东电商的正确打开方式:https://www.ikjzd.com/articles/132558
温州旧货市场有玻璃柜卖吗?:https://www.vstour.cn/a/411246.html
如何用摄影作品表现“芳草鲜美,落英缤纷”的:https://www.vstour.cn/a/411247.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流