0
我试图在路由更改上做简单的淡入淡出动画,但它不起作用。Angular 4路由更改动画
我的动画文件是这样的:
export class RouterAnimations {
static animate() {
return trigger('routerTransition', [
state('void', style({ opacity: 0 })),
state('*', style({ opacity: 1 })),
transition(':enter', [
style({ opacity: 0 }),
animate('0.4s ease')
]),
transition(':leave', [
style({ opacity: 1 }),
animate('0.4s ease')
])
]);
};
};
我的组件是这样的:
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['../vitrine.component.css', './home.component.css'],
animations: [RouterAnimations.animate()]
})
export class HomeComponent implements OnInit {
@HostBinding('@routerTransition')
public routerTransition = true;
constructor() { }
ngOnInit() {
}
}
我发现,如果我把状态的position: fixed
,它的工作原理,但是当动画完成该视图已修复,并且应用程序中的布局被破坏。
它没有工作添加
position: 'relative'
。我改变了状态中的不透明度,并且工作正常,但动画突然完成而不用等待配置的时间。 – tiagor87尝试将您的家庭内容移至子组件并让HomeComponent仅处理动画 –
同样的问题,动画会突然停止。 – tiagor87