首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在animate.css中使用ng动画

在animate.css中使用ng动画
EN

Stack Overflow用户
提问于 2015-01-17 00:07:05
回答 1查看 3.3K关注 0票数 0

我正在尝试理解和使用ngAnimate。

我使用的是角动画.‘m,animate.css和角1.3.

现在,我已经在我的应用程序conf ngAnimate上添加了激活它的内容,并在我的css中添加了类似这样的内容:

代码语言:javascript
复制
.ng-leave{
   -webkit-animation-name: fadeInUp;
   -moz-animation-name: fadeInUp;
   -o-animation-name: fadeInUp;
   animation-name: fadeInUp;
}

它的工作是因为,fadeInUp是在animate.css中声明的。

所以,现在我想不写css就做同样的事情(只使用animate.css)。

我试过这样的方法,但不起作用

代码语言:javascript
复制
<li class="list cars" ng-repeat="item in cars track by item.id" ng-animate="{enter: 'fadeInUp animated', leave: 'fadeOutUp animated'}">

知道吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-17 01:37:51

步骤:-

1)提供抚养:-

代码语言:javascript
复制
angular.module('yo', [
        'ngAnimate'
    ]);

在脚本标记中添加“角-动画.min.js”。

2)执行动画的方法有三种:- a)CSS转换。( b) CSS关键帧动画c) JavaScript动画。

3)选择上述任何一个:-例如,如果您的模板是

代码语言:javascript
复制
<div ng-init="on=true">
  <button ng-click="on=!on">Toggle On/Off</button>
  <div class="my-special-animation" ng-if="on">
    This content will enter and leave
  </div>
</div>

在元素中添加CSS转换所需的类属性,只需添加以下css:-

代码语言:javascript
复制
.my-special-animation.ng-enter {
  -webkit-transition:0.5s linear all;
  transition:0.5s linear all;

  background:red;
}

/* destination animations */
.my-special-animation.ng-enter.ng-enter-active {
  background:blue;
}

柱塞:- http://plnkr.co/edit/?p=preview

CSS关键帧动画比转换更广泛,它们被相同的浏览器( IE9和下面的浏览器除外)所支持。CSS命名样式类似,但不需要使用-active类,因为关键帧动画是在CSS @keyframes声明块中完全管理的。

代码语言:javascript
复制
.my-special-animation.ng-enter {
  -webkit-animation:0.5s red-to-blue;
  animation:0.5s red-to-blue;
}

@keyframes red-to-blue {
  from { background:red; }
  to { background:blue; }
}

@-webkit-keyframes red-to-blue {
  from { background:red; }
  to { background:blue; }
}

柱塞:- http://plnkr.co/edit/?p=preview

如果您想要执行具有更多控件的动画,则可以始终使用JavaScript动画。这是通过在模块代码中定义类似工厂的函数来实现的,如下所示:

代码语言:javascript
复制
myApp.animation('.my-special-animation', function() {
  return {
    enter : function(element, done) {
      jQuery(element).css({
        color:'#FF0000'
      });

      //node the done method here as the 2nd param
      jQuery(element).animate({
        color:'#0000FF'
      }, done);

      return function(cancelled) {
        /* this (optional) function is called when the animation is complete
           or when the animation has been cancelled (which is when
           another animation is started on the same element while the
           current animation is still in progress). */
        if(cancelled) {
          jQuery(element).stop();
        }
      }
    },

    leave : function(element, done) { done(); },
    move : function(element, done) { done(); },

    beforeAddClass : function(element, className, done) { done(); },
    addClass : function(element, className, done) { done(); },

    beforeRemoveClass : function(element, className, done) { done(); },
    removeClass : function(element, className, done) { done(); },

    allowCancel : function(element, event, className) {}
  };
});

柱塞:- http://plnkr.co/edit/?p=preview

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27994706

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档