Is it possible to pause animations in Angular 2+? I would like to pause an animation upon mousing over an element and resume the animation from where it left off when mousing out.
I have created a simple script to demonstrate: https://stackblitz.com/edit/scrolling-text
Here's my component:
import { Component, ElementRef, ViewChild } from '@angular/core';
import { trigger, state, style, animate, transition } from '@angular/animations';
@Component({
selector: 'my-app',
template: `
<div class="container">
<div class="scrolling-text" [@scroll]="state" (@scroll.done)="scrollDone()">Hover to pause!</div>
</div>
`,
styles: [`
.container {
height: 30px;
overflow: hidden;
position: relative;
width: 100%;
}
.scrolling-text {
position: absolute;
white-space: nowrap;
}
/* Below doesn't work to pause */
.scrolling-text:hover, .container:hover {
-moz-animation-play-state: paused;
-webkit-animation-play-state: paused;
animation-play-state: paused;
}
`],
animations: [
trigger('scroll', [
state('on', style({left: '-100px'})),
transition('* => *', [
style({left: '-100px'}),
animate(10000, style({left: '100%'}))
])
])
]
})
export class AppComponent {
state = 0;
scrollDone() {
this.state++;
}
}
I tried animation-play-state: paused;
without luck:
.scrolling-text:hover, .container:hover {
-moz-animation-play-state: paused;
-webkit-animation-play-state: paused;
animation-play-state: paused;
}
Is there any way to get this to work?