Hijacking this a bit but what happens if I have a situation where I'm using the addClass/removeClass and a timeline. I'm not sure if this is the right approach or not as the class could be applied and removed to an element quite rapidly, before the previous animation has completed potentially. I'm seeing growing memory usage which I think it might be doing this wrong as I have the timeline variable outside the addClass/removeClass, which feels a bit wrong. I have a feeling that timelines are getting orphaned but still running their animation loops.
.animation('.sample', ['$animate', function ($animate) {
var tl;
return {
addClass: function (element, className, doneFn) {
var images = element[0].getElementsByTagName('img');
tl = new TimelineMax({ repeat: -1 });
tl.staggerTo(images, 0.2, { y: -40 }, 0.2);
doneFn();
},
removeClass: function (element, className, doneFn) {
if (tl)
tl.clear();
doneFn();
}
}
}])