[英]AngularJS $animateCss on both page load and view change
I use this controller to grab blog posts: 我使用此控制器抓取博客文章:
appCtrl.controller('NewsCtrl', ['$scope', '$http',
function ($scope, $http) {
var posts = [];
$http.get("https://www.googleapis.com/blogger/v3/blogs/BLOG_ID/posts?&key=MY-API-KEY")
.then(function (response) {
posts = response.data;
$scope.items = posts.items;
});
console.log($scope);
}
]);
Then display them on the page like this: 然后像这样在页面上显示它们:
<div ng-repeat="item in items" class="repeat_animation" animate-on-load>
<h2>{{item.title}}</h2>
<span ng-bind-html="item.content"></span>
</div>
I have the following css to animate each returned post: 我有以下CSS为每个返回的帖子制作动画:
.repeat_animation {
&.ng-enter-stagger,
&.ng-leave-stagger,
&.ng-move-stagger {
-webkit-transition-delay: .2s;
transition-delay: .2s;
transition-duration: 0s;
-webkit-transition-duration: 0s;
}
&.ng-enter,
&.ng-leave,
&.ng-move {
-webkit-transition: .5s ease-in-out all;
transition: .5s ease-in-out all;
}
&.ng-leave.ng-leave-active,
&.ng-enter,
&.ng-move {
opacity: 0;
}
&.ng-leave,
&.ng-move.ng-move-active,
&.ng-enter.ng-enter-active {
opacity: 1;
}
}
The items animate in sequence if I load/reload the News view directly but they all animate at the same time if I change to a different page view and then go back again. 如果我直接加载/重新加载“新闻”视图,则这些项目将按顺序进行动画处理,但是如果我更改为其他页面视图,然后再次返回,则它们将同时进行动画处理。
However by invoking the following directive they do animate each time I navigate from one page view to the News view but they don't animate if I reload the page without navigating to it from another view. 但是,通过调用以下指令,它们会在我每次从一个页面视图导航到“新闻”视图时进行动画处理,但是如果我重新加载页面而不从另一视图导航到该页面则它们不会进行动画处理。
app.directive('animateOnLoad', ['$animateCss', function ($animateCss) {
return {
'link': function (scope, element) {
$animateCss(element, {
'event': 'enter',
structural: true
}).start();
}
};
}]);
How can I force posts to always animate sequentially each time the page view is accessed, either directly or on view change? 如何在每次访问页面视图时(无论是直接访问视图还是更改视图)强制帖子始终按顺序进行动画处理?
In the end, the only way I could get staggering to work on page load and view change was by setting the from/to opacity style in the directive like this: 最后,让我费解地处理页面加载和视图更改的唯一方法是通过在伪指令中设置from / to opacity样式,如下所示:
app.directive('animateOnLoad', ['$animateCss', function ($animateCss) {
return {
'link': function (scope, element) {
$animateCss(element, {
event: 'enter',
structural: true,
from: { 'opacity': 0 },
to: { 'opacity': 1 }
}).start();
}
};
}]);
I could not get it to work using css classes from the stylesheet (except intermittently using angular-animate.js version 1.4.3) 我无法使用样式表中的CSS类来工作(除非间歇性地使用angular-animate.js版本1.4.3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.