import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@NgModule({
imports: [
BrowserAnimationsModule
import { AnimationEntryMetadata, state } from '@angular/core';
import { trigger, transition, animate, style, query, group } from '\@angular/animations';
export const routeAnimation: AnimationEntryMetadata =
trigger('routeAnimation', [
transition(':enter', [
style({
position: 'absolute'
}),
animate('0.5s ease-in-out')
]),
transition('* => *', [
query(':leave', style({ transform: 'translateX(0)', position: 'absolute'}), { optional: true }),
query(':enter', style({ transform: 'translateX(100%)', position: 'absolute'}), { optional: true }),
group([
query(':leave', animate('.5s ease-in-out', style({transform: 'translateX(-100%)'})), { optional: true }),
query(':enter', animate('.5s ease-in-out', style({transform: 'translateX(0)'})), { optional: true })
])
])
]);
import { Router, NavigationEnd } from '@angular/router';
import { routeAnimation } from './animations';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.less'],
animations: [routeAnimation]
})
// router跳转动画所需参数
routerState: boolean = true;
routerStateCode: string = 'active';
this.router.events.subscribe(event => {
if (event instanceof NavigationEnd) {
// 每次路由跳转改变状态
this.routerState = !this.routerState;
this.routerStateCode = this.routerState ? 'active' : 'inactive';
}
});
<div id="app" [@routeAnimation]="routerStateCode"> <router-outlet></router-outlet> </div>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有