While attempting to create a slideshow that fades images in and out I ran into this problem. What I found is that when doing animations one at a time, they are smooth and seamless. However when doing multiple animations, they become choppy and erratic. Here is the code I'm using for fading one image in, while at the same time, fading a overlapping image out (all happens in a directive):
var fadeToNextImg = function() {
var nextImg = imageHandler.getNextImage();
$animate.addClass(curImage, 'ng-hide');
$animate.removeClass(nextImg, 'ng-hide');
curImage = nextImg;
};
This works, however the animation produces erratic results. The images don't fade in and out smoothly, instead they just appear, or sometime one of the images will fade. However if I nest the animations so that only one happens at a time then both animations excecute perfectly, one right after the other, like so:
var fadeToNextImg = function() {
var nextImg = imageHandler.getNextImage();
$animate.addClass(curImage, 'ng-hide', function() {
$animate.removeClass(nextImg, 'ng-hide');
curImage = nextImg;
});
};
That's great.. just not the desired effect I wanted. I want for one image to fade out while the other image seamlessly fades in on top of it! Am I doing something wrong? Or is this a bug/performance issue in Angular Animate library?
Another thing to be aware of, I also tried this using JQuery DOM manipulation outside of a directive, and the animation was flawless. I only moved it to a directive because that is the angular way of doing things. So why does it jack up my animations?