Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  3] [ 1]  / answers: 1 / hits: 24936  / 11 Years ago, tue, december 17, 2013, 12:00:00

I try to animate the change of a ng-view div in AngularJS.



So my div inside my index.html file looks like:



<div ng-view></div>


I have another html-file (view1.html) with just divs inside.



My app.js with the routing looks like:



app.config(function($routeProvider) {
$routeProvider
.when('/sites/:templateID',
{
controller: 'simpleController',
templateUrl:'templates/question.html'
})
});


I am changing the path with a click on a button, and call this:



$location.path(/sites/ + nextID);


The URL changes of the site, and only the ng-view-div gets updated. But when i am applying a ng-animation to it:



<div class=content data-ng-view ng-animate={enter: 'animate-enter', leave: 'animate-leave'}></div>


It doesn't work. I included AngularJS 1.2.5, the animate-js file inside my index.html and also my CSS:



.animate-enter, .animate-leave {
-webkit-transition:all 2s ease;
-moz-transition:all 2s ease;
-o-transition:all 2s ease;
transition:all 2s ease;
}

.animate-enter {
left: -100%;
}

.animate-enter.animate-enter-active {
left: 0;
}

.animate-leave {
left: 0;
}

.animate-leave.animate-leave-active {
left: 100%;
}


Is there a way to animate the ng-view change through route-(URL)-changing?


More From » css

 Answers
25

There are a few changes to the CSS rules with Angular Animation 1.2+. ng-animate directive is no longer used so AngularJS now changes the class of the element based on events, such as hide, show, etc.



You can define these like so in your CSS:



.toggle {
-webkit-transition: all 0 cubic-bezier(0.25, 0.46, 0.45, 0.94);
-moz-transition: all 0 cubic-bezier(0.25, 0.46, 0.45, 0.94);
-ms-transition: all 0 cubic-bezier(0.25, 0.46, 0.45, 0.94);
-o-transition: all 0 cubic-bezier(0.25, 0.46, 0.45, 0.94);
transition: all 0 cubic-bezier(0.25, 0.46, 0.45, 0.94);
/* easeOutQuad */
-webkit-transition-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94);
-moz-transition-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94);
-ms-transition-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94);
-o-transition-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94);
transition-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94);
/* easeOutQuad */
}

.toggle.ng-enter {
opacity: 0;
transition-duration: 250ms;
-webkit-transition-duration: 250ms;
}

.toggle.ng-enter-active {
opacity: 1;
}

.toggle.ng-leave {
opacity: 1;
transition-duration: 250ms;
-webkit-transition-duration: 250ms;
}

.toggle.ng-leave-active {
opacity: 0;
}

.toggle.ng-hide-add {
transition-duration: 250ms;
-webkit-transition-duration: 250ms;
opacity: 1;
}

.toggle.ng-hide-add.ng-hide-add-active {
opacity: 0;
}

.toggle.ng-hide-remove {
transition-duration: 250ms;
-webkit-transition-duration: 250ms;
display: block !important;
opacity: 0;
}

.toggle.ng-hide-remove.ng-hide-remove-active {
opacity: 1;
}


That way when you have your HTML element you really only have to define the class=toggle for example. When your app runs Angular will append the classes appropriately.



Here is a good resource for different animation techniques by Augus



And here is a break down of the changes in AngularJS Animations


[#73698] Sunday, December 15, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
melinal

Total Points: 367
Total Questions: 101
Total Answers: 96

Location: Nauru
Member since Thu, Feb 2, 2023
1 Year ago
;