如何在我的情况下创建淡入淡出动画

时间:2014-12-12 07:03:46

标签: css angularjs animation

我正在尝试为ng-show创建淡入和淡出功能。我已阅读了很多帖子,但似乎他们使用的是旧的Angular版本。

我有类似

的东西
<button ng-click="play()"></button>
<div id='wrapper' ng-show="animate" 
                  ng-animate="{show:'animate-show', hide:'animate-hide'}">
TEST HERE</div>

JS

$scope.animate = false;
$scope.play = function() {
    $scope.animate = true;   
}

CSS

.animate-show, .animate-hide {
  -webkit-transition:all linear 1s;
  -moz-transition:all linear 1s;
  -ms-transition:all linear 1s;
  -o-transition:all linear 1s;
  transition:all linear 1s;

}

.animate-show {
  opacity:0;
}

.animate-show.animate-show-active {
  opacity:1;
}

.animate-hide {
  opacity:1;
}

.animate-hide.animate-hide-active {
  opacity:0;
}

以上代码仅显示和隐藏元素,但不提供动画。有没有人知道如何动画它?谢谢!

1 个答案:

答案 0 :(得分:0)

添加angular-animate.js文件

将依赖模块添加为

 angular.module('myApp', ['ngAnimate']);

并修改css

.animate-show,
.animate-hide {
   -webkit-transition:all linear 1s;
   -moz-transition:all linear 1s;
   -ms-transition:all linear 1s;
   -o-transition:all linear 1s;
   transition:all linear 1s;
}

.animate-show.ng-hide-remove,
    .animate-hide.ng-hide-add.ng-hide-add-active {
    opacity: 0;
    display: block !important;
}

.animate-hide.ng-hide-add,
.animate-show.ng-hide-remove.ng-hide-remove-active {
     opacity: 1;
     display: block !important;
 }

ng-animate更改为class

<div id='wrapper' ng-show="animate" class="animate-show animate-hide">TEST HERE</div>

这是演示Plunker