javascript - ng-animate 没有按预期工作

标签 javascript css angularjs ng-animate ng-show

当 bool 变量设置为 true 时,我正在尝试对元素进行简单的淡入。之前它运行良好,直到我将 AngularJS 版本更改为 1.2.15。我做错了什么吗?

Here is a sample JSFiddle.

<div ng-app="myApp" ng-controller="myController">
    {{ready}}
    <div ng-show="ready" ng-animate="{show:'animate-show'}">hello</div>
</div>

$scope.ready = false;

function displayBox() {
    $scope.ready = true;
    $scope.$apply();
}
setTimeout(displayBox, 1000);

最佳答案

Angular 1.2.x 中的动画语法发生了变化。现在您必须使用 ngAnimate 模块作为依赖项并更改使用 CSS 应用动画的方式。您的 HTML 变为:

<div class="animate-show" ng-show="ready">hello</div>

在您的情况下,您只需要这个简单的 CSS:

.animate-show {
    opacity: 1;
    -webkit-transition: all linear 0.5s;
    transition: all linear 0.5s;
}
.animate-show.ng-hide {
    opacity: 0;
}

演示:http://plnkr.co/edit/nHZ6P6evV2Ee4NtIeMZY?p=preview

关于javascript - ng-animate 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25408751/

相关文章:

javascript - Chrome 扩展 - 从弹出窗口执行简单的 JavaScript

javascript - 是否可以通过功能将开关按钮设置为真?

javascript - 添加行后如何避免下拉重复[AngularJS]

javascript - 在 Google Chrome 中使用 AngularJS 重置包含文本的 HTML5 "number"字段

javascript - 在 IE 7 的对象和特定子项的 CSS 中更改颜色

javascript - 如何在javascript中使用类型变量?

javascript - 如何操作JSON数据?

javascript - 'this' 在 function() 中未定义。 Angular 2

jQuery - 比较两个数字并将背景属性添加到最大

javascript - 在 JS 中等效于应用于 SVG 元素的调整大小的 css