脚本宝典收集整理的这篇文章主要介绍了angular2系列之动画-路由转场动画,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
一.在app.mudule.ts中引入:
import { browserAnimationsModule } From '@Angular/platform-browser/animations';
并在@NgModule中的imports添加:
imports: [BrowserAnimationsModule],
二.创建文件定义名为animations.ts用来书写转场动画
import { aniMATE, AnimationEntryMetadata, state, style, transITion, trigger } from'@angular/core';
// component transition animations
export const slideinDownAnimation: AnimationEntryMetadata =
// 动画触发器名称
trigger('routeAnimation', [
state('*',
style({
opacity: 1,
transform: 'translatex(0)'
})
),
transition(':enter', [
style({
opacity: 0,
transform: 'translateX(-100%)'
}),
animate('0.2s ease-in')
]),
transition(':leave', [
animate('0.5s ease-out', style({
opacity: 0,
transform: 'translateY(100%)'
}))
])
]);
三.在需要添加转场动画的页面操作
引入import {HostBinding } from '@angular/core';(如果引入过直接将HostBinding添加进去就好,不要重复引入,多嘴了...)
再引入你写好的动画模板:import { slideInDownAnimation } from '../animation';
在@Component中添加:animations:[slideInDownAnimation],
最后:
// 添加@HostBinding属性添加到类中以设置这个路由组件元素的动画和样式
@HostBinding('@routeAnimation') routeAnimation = true;
@HostBinding('style.display') display = 'block';
@HostBinding('style.position') position = 'absolute';
四.至此你可以去浏览器看看效果了,如果没有错误
以上是脚本宝典为你收集整理的angular2系列之动画-路由转场动画全部内容,希望文章能够帮你解决angular2系列之动画-路由转场动画所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。