【发布时间】:2015-04-04 05:52:35
【问题描述】:
我一直在 Google 和 Stackoverflow 上搜索,但没有找到我要找的东西。
这就是我所拥有的。我保证我会真诚地努力解决这个问题。
问题如下:我有动画处理列表。当我使用超时将项目添加到列表中时,它们会正确地动画化。但是,“title”变量是一个字符串。我想在此值更改时应用动画。老实说,我现在仍然对如何让它发挥作用一无所知。我知道我可以为 ng-hide 的动画添加 css 类,但我仍然不太明白如何在这里适应它。提前感谢任何帮助。请赐教。你不必给我代码。即使是对如何实现这一点的高级描述也足够了。
// app.js
(function() {
var app = angular.module("MyApp", ["ngAnimate"]);
// route configuration
}());
// homecontroller.js
(function() {
var app = angular.module("MyApp");
app.controller("HomeController", ["$scope","$timeout", homeController];
function homeController($scope, $timeout) {
$scope.items = ["Frodo", "Bilbo", "Merry", "Pippin", "Sam"];
$scope.title = "The Hobbits";
$timeout(function() {
$scope.title = "The Hobbits and the Wizard";
$scope.items.unshift("Aragorn","Faramir","Boromir");
}, 5000);
}
}());
一些 HTML
<!-- view for HomeController -->
<h1>{{ title }}</h1>
<div ng-controller="HeaderWebpart.HeaderController">
<div class="testClass" style="display:block;" ng-repeat="item in items">{{ item }}</div>
</div>
还有 CSS
div.testClass.ng-enter {
-webkit-animation: enter 1000ms cubic-bezier(0.250, 0.100, 0.250, 1.000);
animation: enter 1000ms cubic-bezier(0.250, 0.100, 0.250, 1.000);
display: block;
position: relative;
}
@-webkit-keyframes enter {
from {
opacity: 0;
height: 0px;
left: -70px;
}
75% {
left: 15px;
}
to {
opacity: 1;
height: 20px;
left: 0px;
}
}
div.testClass.ng-enter-active {
opacity: 1;
}
【问题讨论】:
-
此站点可能会有所帮助:daneden.github.io/animate.css。如您所见,实际动画运行时有一个
.animate类。此外,还可以添加一个.infinite类以不断重复动画(不超过设定的时间)。 -
感谢您发布此信息 - 非常有帮助。
标签: javascript css angularjs animation