带有css3转换的角度淡入淡出动画

我正在尝试使用ngAnimate和css3过渡点击链接淡入/淡出div . 我有以下,但它不起作用 . div显示/隐藏,但不会淡入或淡出 . 我哪里做错了:

.fade-in-out.ng-add {
  transition: 1s linear all;
  opacity: 0;
}

.fade-in-out.ng-add-active {
  opacity: 1;
}

.fade-in-out.ng-remove {
  transition: 1s linear all;
  opacity: 1;
}

.fade-in-out.ng-remove-active {
  opacity: 0;
}

div最初是隐藏的( showMe = false) . 在页面上是一个将 showMe 设置为true的链接 .

<div ng-show="showMe" class="fade-in-out">          
    <div style="float: right; cursor: pointer;" ng-click="showMe=false">x</div>
    blablabla
</div>

请注意,我使用角度1.2.26 .

回答(1)

3 years ago

要使用的正确类是:

.my-element.ng-hide-add, .my-element.ng-hide-remove {
  transition:0.5s linear all;
}

.my-element.ng-hide-add { ... }
.my-element.ng-hide-add.ng-hide-add-active { ... }
.my-element.ng-hide-remove { ... }
.my-element.ng-hide-remove.ng-hide-remove-active { ... }

在你的情况下,这就足够了:

.fade-in-out {
  transition: 1s linear all;  
  opacity: 1;
}

.fade-in-out.ng-hide {
  opacity: 0;
}

Demo: http://plnkr.co/edit/WM60wEYeQD7J1GuHG0WL?p=preview

请注意,必须加载 angular-animate.js 并且必须将 ngAnimate 添加为依赖模块 .