简体   繁体   English

AngularJS $ animateCss在页面加载和视图更改上

[英]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.

相关问题 在AngularJS中无需加载即可查看前一页数据 - View previous page data without load in AngularJS AngularJs重新加载页面而不是仅加载视图 - AngularJs reload page instead only load view 页面加载调用事件的两个下拉列表更改 - On page load call change of events for both dropdown AngularJS-在选择下拉列表更改时更新页面视图 - AngularJS - updating page view on select dropdown change HTML页面视图页面源未显示从angularjs加载的内容 - HTML Page view page source not showing content load from angularjs AngularJS错误未知提供程序:$$ jqLit​​eProvider &lt;-$$ jqLit​​e &lt;-$ animateCss &lt;-$ uibModalStack &lt;-$ uibModal - AngularJS Error Unknown provider: $$jqLiteProvider <- $$jqLite <- $animateCss <- $uibModalStack <- $uibModal 在单页面应用程序中使用Angularjs单击按钮时加载视图 - Load view on button click with Angularjs in single page application 在SPA应用程序中使用AngularJs在ng-view中加载外部页面 - Load external page inside ng-view with AngularJs in an SPA application 在视图页面上加载执行控制器功能,angularjs方式 - on view page load execute controller function, angularjs way angularjs-$ state.go更改URL,但不加载HTML页面 - angularjs - $state.go change url but not load html page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM