Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upPossibility to have a loop animation, using triggers. [Feature Request] #20621
Comments
|
It would be great if iterations were defined the following ways:
|
|
@leonardopaiva Have you managed to make an infinite animation? Could you show an example? Unfortunately I tried by looping states but that crashed the browser :(. I have also tried adding a timeout but it didn't loop properly either and also delayed ssr. |
|
@nekkon basically you need to use the animation done event that you can attach to the trigger, this event will give you a parameter with the event, it contains the end state, so using that you can swap between start and end states, but this is just a work around. I will up a repository with the example, as soon as possible, i will be back from a trip near January 3 to 5. Another workaround is to make a basic css animation loop using keyframes, depends a lot on the case. |
|
Exactly. I support this idea. I'm surprised Angular 5 animation feature doesn't ship with built-in loop function. You'll have hard time to properly looping angular animation. CSS3 has loop count built in. You can set a number of times you want your animation to loop. Angular animations should come with the same loop function. |
|
Angular 6 should come with animation loop. Hopefully Google will make this happen. |
|
awesome @jamesharvey2 @nekkon sry for the delay, but i finally created the loop demo "workaround" you can see it here hope that it helps you or another person with the same need. |
|
amazing... so it uses event fired when animation is finished. Still I would like to see 'iteration-count' properly implemented on Angular 6. |
|
yeah @jamesharvey2 this is just a work around, the ideal would be something like: will make it repeat until the state changes:
or will make it repeat 3 times
|
|
Yeah, iteration count should be implemented in Angular 6. I hope Google guys find this feature request. |
|
I would say it's time to abandon angular animations permanently. http://animejs.com/documentation/#loop I realized Angular animations is a waste of time. It's buggy, it has limitations and 'BrowserAnimationsModule' is extremely sensitive. It crashes the whole app for a tiny bit of mistake. |
And thank you for throwing an error instead of auto-magically not working and doing whatever the heck you think you should do to "correct" my mistake.
You do realize that Angular is open-source? You're free to jump in to help "create something that can beat Anime.js". |
|
@jamesharvey2
By the way, I see that the Animation Player has a restart method. Haven't tried it, but If it does what it intuitively says it does, you could use the player to handle a looping animation and OR I guess... ultimately you could use plain old css to create that one infinite loop animation you need in a project (not an |
|
I'm not sure if it will help somebody out, but I have found a really nice infinity workaround. |
|
Here's how I implemented repeating an animation n times: @ViewChild('animateEl', { read: ElementRef }) animateEl: ElementRef;
constructor(private _builder: AnimationBuilder) { }
private runAnimationNTimes(n: number) {
// IMPORTANT: for some reason `const animation` needs to be declared in this function
// If it's declared outside, animation does not work properly.
const animation = animate('10s ease-out', keyframes([
style({ offset: 0, transform: 'rotate(0)' }),
// more styles here...
]));
const factory = this._builder.build(animation);
const player = factory.create(this.animateEl.nativeElement);
player.onDone(() => {
player.destroy();
if (n > 1) {
this.runAnimationNTimes(--n);
}
});
player.play();
} |
|
it's so weird. when i use AnimationBuilder Service to create animationPlayer, the AnimationPlayer's onDestroy callback is never invoked with executing the animationPlayer. destroy() synchronously, but i execute animationPlayer.destroy() asynchronously, everything looks normal, here's how implemented infinite loop:
|
|
@leonardopaiva any updates on the requested feature ? this should have been implemented by now |
|
Hi |


Hello i`m trying to make a loop animation with full control using triggers, right now theres no easy way to make it, only a few possibles work arounds.
I'm submitting a...
Current behavior
Not possible to make a loop inside a trigger config, right now i have to check animation done to swap the trigger back and create the loop.
edit:
sharing the example of how i do now:
https://angular-animations-demo.firebaseapp.com/loop-demo
source here:
https://github.com/leonardopaiva/angular-animation-basic-project/tree/master/src/app/loop-demo
Expected behavior
Something like a parameter to group, query or animate, setting loop true, or the number of repetitions, animate(300, boolLoopTrue) or animate(300, {boolRepetitions: 3}), example:
What is the motivation / use case for changing the behavior?
I`m trying to make complex animations and need it to make things right, stop using work arounds.
Environment
Angular