angular 1.1.5 - http://plnkr.co/edit/eoKt8o4MJw9sWdYdeG3s?p=preview - WORKS
棱角1.2.6 - http://plnkr.co/edit/WopgAtFNVm1mKf5Li99h?p=preview - 失败
我想我确实按照文档中的说明进行操作 - http://docs.angularjs.org/api/ngAnimate
•首先在HTML中包含angular-animate.js
•然后通过将模块添加为依赖模块
来加载应用程序中的模块
我的时区已经很晚了,我可能会错过一些明显的东西。我的猜测是 - 1.1.5和1.2.6之间的CSS文件不兼容?无法真正说出......
无论如何这里是代码形式 upped plunker,我包含了一些评论,强调我遵循了文档中的说明:
<!doctype html>
<html ng-app="app">
<head>
<meta charset="utf-8">
<title>Top Animation</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css">
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="http://code.angularjs.org/1.2.6/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular-animate.js"></script>
<!-- ^^^ load animate -->
</head>
<script>
var app = angular.module('app', ['ngAnimate']); // <-- dependent module
app.controller('Ctrl', function($scope) {
$scope.names = ['Igor Minar', 'Brad Green', 'Dave Geddes', 'Naomi Black', 'Greg Weber', 'Dean Sofer', 'Wes Alvaro', 'John Scott', 'Daniel Nadasi'];
});
</script>
<body ng-controller="Ctrl">
<div class="well" style="margin-top: 30px; width: 200px; overflow: hidden;">
<form class="form-search">
<div class="input-append">
<input type="text" ng-model="search" class="search-query" style="width: 80px">
<button type="submit" class="btn">Search</button>
</div>
<ul class="nav nav-pills nav-stacked">
<li ng-animate="'animate'" ng-repeat="name in names | filter:search">
<a href="#"> {{name}} </a>
</li>
</ul>
</form>
</div>
</body>
</html>
答案 0 :(得分:36)
以下是您的plunker的工作版本...... http://plnkr.co/edit/05irGvYwD4y9ZRb1ZHSw?p=preview
在Angular 1.2+中,您不再需要声明ng-animate指令。动画可以单独添加css。因此,对于您的示例,您可以删除ng-animate指令并为该元素指定一个css类,因此请更改...
<li ng-animate="'animate'" ng-repeat="name in names | filter:search">
to...
<li class="animate" ng-repeat="name in names | filter:search">
然后将您的CSS更新为...
.animate.ng-enter,
.animate.ng-leave
{
...
.animate.ng-leave.animate.ng-leave-active,
.animate.ng-enter {
...
.animate.ng-enter.ng-enter-active,
.animate.ng-leave {
...
Angular会简单地将ng-enter,ng-hide,ng-leave ...等类添加到元素中,并在动画生命周期中适当地删除它们,这将触发css动画。有一个列表,其中的指令支持“使用”下docs中的哪些动画类。在这个例子中,我们是动画ng-repeat,所以ng-enter,ng-leave和ng-move类将在适当的时候添加到我们的元素中,我们可以用css将动画附加到它们。
答案 1 :(得分:2)
我发现这个演示效果很好: http://jsbin.com/usaruce/3/edit
它使用以下语法:
.todo-item {
-webkit-transition: color 0.6s, background-color 0.3s;
-moz-transition: color 0.6s, background-color 0.3s;
-ms-transition: color 0.6s, background-color 0.3s;
transition: color 0.6s, background-color 0.3s;
}
.todo-item.ng-enter {
-webkit-animation: fadeInLeft 1s;
-moz-animation: fadeInLeft 1s;
-ms-animation: fadeInLeft 1s;
animation: fadeInLeft 1s;
}
.todo-item.ng-leave {
-webkit-animation: bounceOut 1s;
-moz-animation: bounceOut 1s;
-ms-animation: bounceOut 1s;
animation: bounceOut 1s;
}
它还利用了animate.css (fadeInLeft,bounceOut)