In my Meteor app I have some complex page animations that require a few seconds to complete (instructive animations take priority over page transition speed).
There's an out state and an in state in the animation. For simplicity's sake, let's say I need to fade out one page, and then fade in the next, but that I want those fades to take multiple seconds. To do this I use Meteor's Iron Router to call some animation functions that manipulate the CSS.
lib/router.js
animateContentOut = function(pause) {
return $('#content').removeClass("animated fadeIn");
}
Router.onAfterAction(animateContentOut);
animateContentIn = function() {
return $('#content').addClass("animated fadeIn");
}
Router.onAfterAction(animateContentIn);
This is based on a great tip from Manuel Schoebel and the fadeIn works. However, my fade animation takes several seconds. So the user only sees the first few miliseconds of the fadeOut animation because it starts and then the router quickly navigates away to the new route before the animation completes.
So my question, is: how can I tell the router to wait for the animation to complete or for a setTimeout on an action in the onAfterAction call? Is there a better hook to use when animating the process of leaving a page?