【发布时间】:2015-01-18 22:11:16
【问题描述】:
我有一个要制作动画的应用程序,但我似乎无法弄清楚为什么没有添加类。我在页面上包含了脚本,添加了 ngAnimate 依赖项(它允许我注入 $animate 所以我认为这是一个很好的检查,看看它是否实际加载了?)。我的设置相当简单,这使得它无法正常工作更加令人沮丧。我正在尝试为 ng-repeat 设置动画。
为了保持帖子简短,我在关键帧中省略了供应商前缀,但我的 less 文件中确实有它们。当我检查 chrome 中的元素并手动添加 ng-leave 作为类时,它会按应有的动画效果,所以我很确定我的动画很好,只是 ngAnimate 没有像我期望的那样添加类。我的 css 文件中可能缺少某些内容。我能找到的最让我感到困惑的是这个链接:
Installation of ngAnimate Module not working
它声明 ngAnimate 不会添加类,除非你没有设置特定的 CSS 规则。我很困惑我的 &.ng-leave 是否足以让 ngAnimate 接受它,还是我需要添加更多?如果重要的话,我的 ng-repeat 也在指令模板中。页面上的一切都很好,只是没有动画触发器。
在过去的几个小时里,我一直在查看与遇到此问题的人远程相关的任何链接,并尝试了我找到的所有方法,但没有任何效果。代码如下
//css
@keyframes rollOut {
from {
opacity: 1;
}
to {
opacity: 0;
-webkit-transform: translate3d(100%, 0, 0) rotate3d(0, 0, 1, 120deg);
-moz-transform: translate3d(100%, 0, 0) rotate3d(0, 0, 1, 120deg);
-ms-transform: translate3d(100%, 0, 0) rotate3d(0, 0, 1, 120deg);
-o-transform: translate3d(100%, 0, 0) rotate3d(0, 0, 1, 120deg);
transform: translate3d(100%, 0, 0) rotate3d(0, 0, 1, 120deg);
}
}
.roll-out.ng-leave {
-webkit-animation: rollOut 5s linear;
-moz-animation: rollOut 5s linear;
-o-animation: rollOut 5s linear;
animation: rollOut 5s linear;
}
//html
<div ng-repeat="item in list track by $index" class="roll-out">
<div>{{ item }}</div>
</div>
//app.js (loaded correctly?)
(function () {
'use strict';
var modules = ['core', 'gui', 'etc'];
var submodules = ['filter', 'service', 'directive'];
var libmodules = ['ui.bootstrap', 'ngAnimate'];
modules.forEach(function(module) {
submodules.forEach(function(sub) {
angular.module(module + '.' + sub, []);
});
angular.module(module, submodules.map(function(a) { return module + '.' + a; }));
});
angular.module('myApp', modules.concat(libmodules));
}());
【问题讨论】:
-
注意,AngularJS 核心中有一个
$animate服务可用,它只执行简单的 DOM 操作。所以这不是检查 ngAnimate 是否加载的好方法。 -
谢谢,我不知道。我在 app.js 中添加以显示我如何加载模块。我的整个应用程序都可以正常工作,并且添加 ngAnimate 并没有给出错误。除此之外,我不知道如何判断它是否已加载
标签: css angularjs animation ng-animate