Looking for a simple solution to my implementation issues. I'm faced with the following DOM setup:
<h1 class="fade" ng-repeat="child in parent.children" ng-show="parent.activeChild == child">@{{ child.title }}</h1>
How can I smoothly fade out the currently active child when the activeChild
property of the parent
model changes, and then fade in the newly active child afterward?
I have a rough working solution using CSS transitions:
.fade.ng-hide-add {
transition: opacity 1s ease;
}
.fade.ng-hide-remove {
transition: opacity 1s ease 1s;
}
.fade.ng-hide-add {
opacity: 1;
&.ng-hide-add-active {
opacity: 0;
}
}
.fade.ng-hide-remove {
opacity: 0;
&.ng-hide-remove-active {
opacity: 1;
}
}
However, this leads to an issue as shown in this example (Plunkr).
I aim to chain my animations. Although I've read the ng-animate docs, I'm struggling with the syntax required to achieve the desired effect.
The Angular docs feature something like this:
app.animation('.fade', [function() {
return {
addClass: function(element, className, doneFn) {
},
removeClass: function(element, className, doneFn) {
}
};
}]);
- What is
className
? Is it the class intended for fading in/out? The expected class? - What does
doneFn
represent? Does it signify a function executed after the animation finishes? What should be included here? - If there is already a
doneFn
, what should be included in theaddClass
andremoveClass
functions?
The Objective
I want to create a functional animation directly using Angular's ngAnimate module, utilizing either CSS or JS. Any tips on achieving this goal?