0
我想在Angular 4组件中动画svg。我如何在svg组件中获取不同的ID并按顺序对它们进行动画处理?在svg动画元素与Angular 4之间切换
我可以通过单击事件触发我的svg单个元素上的单个动画,但是如何在页面加载时触发此动画?
我有以下component.ts代码:
import { Component, OnInit } from '@angular/core';
import { DataService } from '../data.service';
import { trigger, state, style, transition, animate, keyframes } from '@angular/animations';
@Component({
selector: 'app-splash',
templateUrl: './splash.component.html',
styleUrls: ['./splash.component.css'],
animations: [
trigger('myAwesomeAnimation', [
state('offscreen', style({
transform: 'translateY(-50px)',
})),
state('onscreen', style({
transform: 'translateY(50px)',
})),
transition('offscreen => onscreen', animate('500ms 500ms ease-in')),
]),
]
})
export class SplashComponent implements OnInit {
state: string = 'offscreen';
animateMe() {
this.state = (this.state === 'offscreen' ? 'onscreen' : 'offscreen');
}
constructor(private dataService:DataService) {
}
someProperty:string = '';
ngOnInit() {
console.log(this.dataService.cars);
this.someProperty = this.dataService.myData();
}
}
部件的我的HTML部分是比较复杂的,因为的我的SVG的复杂性,但我至今一个动画元素:
<g id="IsEverything" [@myAwesomeAnimation]='state'(click)="animateMe()"> ...
@ Davtho1983你见过这篇文章吗? https://blog.thoughtram.io/angular/2017/07/26/a-web-animations-deep-dive-with-angular.html – JGFMK
我没有谢谢!我看到他的一些其他人 - 我不知道为什么那个特别的人躲过了我 - 看起来它会帮助你! – Davtho1983