如果您在使用Angular动画时遇到多状态下不工作的问题,可能需要遵循以下步骤:
@Component({ selector: 'app-my-component', templateUrl: './my-component.component.html', styleUrls: ['./my-component.component.css'], animations: [ trigger('myTrigger', [ state('one', style({ backgroundColor: 'red', transform: 'scale(1.2)' })), state('two', style({ backgroundColor: 'blue', transform: 'scale(0.8)' })), transition('one => two', [ animate('1s') ]), transition('two => one', [ animate('0.5s') ]) ]) ] }) export class MyComponent { state = 'one';
toggleState() { this.state = (this.state === 'one') ? 'two' : 'one'; } }
transition('one => two', [ animate('1s', style({ opacity: 0 })), animate('2s', style({ opacity: 1 })) ]);
使用这些步骤,您可以确保在多个状态下使用Angular动画时的平稳过渡,并解决此问题。
上一篇:Angular动画与切换按钮