Preventing animations when enabling loading on a page

I created a simple rotating cube animation in a directive ng-viewusing ngAnimatewith Angular 1.2 and getting this CSS:

.cube-container {
  -webkit-transform-style: preserve-3d;
  -webkit-perspective:400px;
  height:100%;
}
.cube.ng-enter, 
.cube.ng-leave { 
  -webkit-transition: 0.8s linear all;
}
.cube.ng-enter {
  -webkit-transform-origin: 100% 50%;  
  -webkit-transform: translateX(-100%) rotateY(-90deg);
}
.cube.ng-enter.ng-enter-active {
  -webkit-transform: translateX(0%) rotateY(0deg);
}

.cube.ng-leave {
  -webkit-transform-origin: 0% 50%;
}
.cube.ng-leave.ng-leave-active {
    -webkit-transform: translateX(100%) rotateY(90deg);
}

The markup is as follows:

<div class="cube-container">
    <div class="app cube" ng-view></div>
</div>

This works great. The problem is this: how to disconnect the animation from the initial loading of the first page and apply it only when changing the route?

Thanks!

+4
source share
2 answers

You need to apply the animation class dynamically, as shown below:

http://jsfiddle.net/J63vD/

I believe that this can be done in any event, such as a route change event.

HTML:

<div ng-app="App">
    <input type="button" value="set" ng-click="myCssVar='css-class'" />
    <input type="button" value="clear" ng-click="myCssVar=''" />
    <span ng-class="myCssVar">CSS-Animated Text</span>
</div>

CSS

.css-class-add, .css-class-remove {
  -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
  -moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
  -o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
  transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
}

.css-class,
.css-class-add.css-class-add-active {
  color: red;
  font-size:3em;
}

.css-class-remove.css-class-remove-active {
  font-size:1.0em;
  color:black;
}

JavaScript:

angular.module('App', ['ngAnimate']);
+1

. , css . js:

myAppModule.run(function($rootScope, $timeout) {
  $timeout(function() {
    $rootScope.pageInited = true;
  }, 5000)
});

html:

<div class="cube-container">
  <div class="app cube" ng-view ng-class="{'page-inited': pageInited}"></div>
</div>

ng- , .

css-, css:

.page-inited.cube.ng-enter, 
.page-inited.cube.ng-leave { 
  -webkit-transition: 0.8s linear all;
}
+1

All Articles