html - Angular 顺序路由器动画

标签 html css angular animation angular-animations

我是 Angular 动画的新手。我想测试具有多个动画阶段的路由器动画。

home page

第一页(主页)有 3 个不同颜色的 div block 。如果我们点击其中一个,它会平滑地缩放到宽度的 100%。

变成100%后如果需要在中间显示一些文字几秒。

1st part of the animation done

紧接着下一页必须显示从中间到放大的正方形动画

The 1st part of the 2nd animation showing a part of next page

Showing some more next page

2nd animation is done

例如它必须经过以下步骤:

放大框必须显示,因为下一页已经在第一页之后了。

如需更多许可,请查看此 websites瓷砖点击动画

我想从 Angular 动画来完成这项任务,而且我对做这种复杂的逐步动画还很陌生。

最佳答案

我无法通过一个动画实现这一点,但我使用了 2 个动画组件来完成它。

对于显示框动画,我不得不在应用程序组件中编写动画。

app.component.html =>

<app-header></app-header>

<nav>
  <a routerLink="/home">Dashboard</a>
  <a routerLink="/next">next</a>
</nav>
<div id="page" class="routeContainer" [@routeAnimation]="getDepth(myOutlet)">
  <router-outlet #myOutlet="outlet"></router-outlet>
</div>

app.component.ts =>

import { Component } from '@angular/core';
import {animate, group, query, style, transition, trigger} from '@angular/animations';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  animations: [
    trigger('routeAnimation', [
      transition('1 => 2', [
        // animate the leave page away
        group([
          query(
            ':enter',
            [
              style({
                position: 'absolute',
                'z-index' : '100',
                opacity: 1,
                height: '100%',
                width: '100%',
                'clip-path': 'polygon(100px 400px, 400px 400px , 400px 500px, 100px 500px)'

              }),
              animate(
                '3s cubic-bezier(.35,0,.25,1)',
                style({
                  opacity: 1,
                  'clip-path': 'polygon(0px 0px, 100% 0px , 100% 100%, 0px 100%)'
                   })
              ),
            ],
            { optional: true }
          ),
          query(
            ':leave',
            [animate('2s', style({ opacity: 1, 'z-index': '0', }))],
            { optional: true }
          )
        ])
      ]),

    ])
  ]
})
export class AppComponent {
  title = 'app';

  getDepth(outlet) {
    return outlet.activatedRouteData['depth'];
  }


}

在路由中我们声明每条路由的深度值,像这样=>

const routes: Routes = [
  { path: '', redirectTo: '/home', pathMatch: 'full' },
  { path: 'home', component: MainComponent, data: {depth: 1} },
  { path: 'next', component: NextComponent, data: {depth: 2} }

];

对于窗帘动画,我在MainComponent里面单独写了动画。

main.component.html

<div class="row main-page">


  <div  [ngClass] ="{'link1-animation' :helpMenuOpen, 'col-sm link1' :!helpMenuOpen }"  (click)="toggle()"
        [@slideInOut]="helpMenuOpen"
        (@slideInOut.done)="animationDone($event)"

  >

    <h1>
      123
    </h1>
  </div>

  <div class="col-sm link2">
  </div>

  <div class="col-sm link3">
  </div>
</div>

main.component.ts

@Component({
  selector: 'app-main',
  templateUrl: './main.component.html',
  styleUrls: ['./main.component.css'],
  animations: [
    trigger('slideInOut', [
      state('true', style({
        'z-index': 2,
        width: '100%',
        left: 0,
        'background-color': 'pink'
      })),
      transition('0 => 1', animate('1s ease'))
    ])
  ]
})


export class MainComponent implements OnInit {

  public helpMenuOpen = false;

  constructor(private router: Router) {
  }

  ngOnInit() {
  }

  toggle() {
    this.helpMenuOpen = !this.helpMenuOpen ;

  }


  animationDone($event) {

    if (this.helpMenuOpen) {

      this.router.navigate(['/next']);
    }

  }


}

我所做的是等到窗帘动画完成并导航到下一页。当导航发生时,我在上面做的路线动画将运行。

关于html - Angular 顺序路由器动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51739423/

相关文章:

javascript - 我可以将关键帧动画的进度设置为特定阶段吗?

javascript - Angular 2 js 中的 ng-src 和 Dart

html - Bootstrap 调整列

css - 在我的叠加层上叠加文字

javascript - 单击时 JQuery 淡出列表元素

html - 设置子 div 的高度 100% 减去固定高度

angular - 如何为包含带 Angular 路由器的组件设置测试?

angular - 如何使用httpclient拦截angular jsonp请求

HTML : Text after empty bold tag also displayed in bold formatting

javascript - 使用 $ ('img[src$="变量中的图像源结束字符串选择图像"]') 得到未定义的值