admin管理员组文章数量:1356267
I want to iterate animation infinitely and stop and start in my ponent. I have written the below code:
@Component({
selector: 'page-login',
templateUrl: 'login.html',
animations: [
// Each unique animation requires its own trigger. The first argument of the trigger function is the name
trigger('run', [transition('void => *',[animate(1000, keyframes([
style({transform: 'translateX(0) rotateY(0)', offset: 0}),
style({transform: 'translateX(10%) rotateY(70deg)', offset: 0.33}),
style({transform: 'translateX(20%) rotateY(30deg)', offset: 0.66}),
style({transform: 'translateX(0%)', offset: 1.0})
]))
])
])
]
})
In the HTML file I have written below code:
<img @run id="animicon" src="assets/.../logo_1.png" style="background:black" class="image--background">
I want to iterate animation infinitely and stop and start in my ponent. I have written the below code:
@Component({
selector: 'page-login',
templateUrl: 'login.html',
animations: [
// Each unique animation requires its own trigger. The first argument of the trigger function is the name
trigger('run', [transition('void => *',[animate(1000, keyframes([
style({transform: 'translateX(0) rotateY(0)', offset: 0}),
style({transform: 'translateX(10%) rotateY(70deg)', offset: 0.33}),
style({transform: 'translateX(20%) rotateY(30deg)', offset: 0.66}),
style({transform: 'translateX(0%)', offset: 1.0})
]))
])
])
]
})
In the HTML file I have written below code:
<img @run id="animicon" src="assets/.../logo_1.png" style="background:black" class="image--background">
Share
Improve this question
edited Apr 11, 2022 at 14:08
Vega
28.7k28 gold badges120 silver badges145 bronze badges
asked Apr 3, 2019 at 6:59
Abhijit ChakraAbhijit Chakra
3,2423 gold badges42 silver badges67 bronze badges
1 Answer
Reset to default 11Using Angular animations would be incorrect in this context. They are intended to be used when the ponent is added via router or *ngIf or programmatically, when the regular/plain CSS cannot be used or wont work.
Adding them would only make your code unnecessarily plexe, even slow.
For the case you described in your post, you don't need an Angular animation, plain css animation is plenty enough:
CSS
@keyframes myAnimation {
0% {transform: translateX(0) rotateY(0)}
33% {transform: translateX(10%) rotateY(70deg)}
66% {transform: translateX(20%) rotateY(30deg)}
100% {transform: translateX(0%)}
}
img {
animation: myAnimation 5s infinite;
}
Demo
However, if you still want to use Angular approach, here is a take.
ts:
.....
animations: [
// Each unique animation requires its own trigger. The first argument of the trigger function is the name
trigger('run', [
transition('* => *', [
animate(
1000,
keyframes([
style({ transform: 'translateX(0) rotateY(0)', offset: 0 }),
style({
transform: 'translateX(10%) rotateY(70deg)',
offset: 0.33,
}),
style({
transform: 'translateX(20%) rotateY(30deg)',
offset: 0.66,
}),
style({ transform: 'translateX(0%)', offset: 1.0 }),
])
),
]),
]),
],
....
trigger: boolean;
ngOnInit() {
setInterval(() => (this.trigger = !this.trigger),1000);
}
HTML:
<img
[@run]="trigger"
.....
/>
demo
本文标签: javascriptHow to iterate an animation infinitely in AngularStack Overflow
版权声明:本文标题:javascript - How to iterate an animation infinitely in Angular - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744034983a2579601.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论