加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何在角度2中为子组件设置动画?

发布时间:2020-12-17 17:36:11 所属栏目:安全 来源:网络整理
导读:我试图在父组件上添加动画,所以当子组件:enter或:leave时,会显示滑动效果.这是我的父亲@component: @component({ selector: 'plan',templateUrl: '../templates/plan.tpl.html',styleUrls: ['../../../../assets/css/plan.scss'],animations: [ trigger('
我试图在父组件上添加动画,所以当子组件:enter或:leave时,会显示滑动效果.这是我的父亲@component:

@component({
   selector: 'plan',templateUrl: '../templates/plan.tpl.html',styleUrls: ['../../../../assets/css/plan.scss'],animations: [
     trigger('stepAnimation',[
       transition(':enter',[
         style({transform: 'translateX(100%)'}),animate('0.5s ease-in-out',style({transform: 'translateX(0%)'}))
       ]),transition(':leave',[  // before 2.1: transition('* => void',[
      style({transform: 'translateX(0%)'}),style({transform: 'translateX(-100%)'}))
    ])
  ])]

})

然后我将动画选择器添加到模板中的子组件,如下所示:

<start *ngIf="currentPage == 'start'" @stepAnimation></start>
<about *ngIf="currentPage == 'about'" @stepAnimation></about>
<family *ngIf="currentPage == 'family'" @stepAnimation></family>

动画不起作用.然后我在每个组件中添加动画代码,并将@stepAnimation添加到每个模板的父标签中.这样,我得到了输入动画,但没有离开.我想这是因为父母的ngIf,但无论如何,有很多重复的动画代码.无论如何都会在父级别上处理动画吗?

解决方法

问题是自定义元素< start>,< family>和< about>没有样式,因此显示默认为内联,无法翻译.只需将其添加到父样式表:

about,start,family {
    display: block;
    /*Any other layout code,e.g. position:absolute */
}

它应该工作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读