小编Zoo*_*All的帖子

角度6动画* ngIf,过渡不起作用

该项目提出了两种动画变体。

动画选项1,trigger('animationOption1')
工作正常,没有任何抱怨。

动画选项2,trigger('animationOption2')
过渡在这里不起作用。

在StackBlitz.com上在线检查该项目

app.component.html

<h1>Animation Option 1</h1>
<div (click)="changeDivState()"
     [@animationOption1]="clickedDivState"
>Click Me
</div>

<h1>Animation Option 2</h1>
<button (click)="toggleMenu()">Click Me</button>
<ul *ngIf="isMenuOpen"
    [@animationOption2]="isMenuOpen ? 'open': 'close'"
>
  <li>Menu Item 1</li>
  <li>Menu Item 2</li>
  <li>Menu Item 3</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

app.component.ts

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  animations: [
    trigger('animationOption1', [
      state('start', style({
        backgroundColor: 'yellow',
        width: '150px',
        height: '150px'
      })),
      state('end', style({
        backgroundColor: 'green',
        width: '300px',
        height: '300px'
      })),
      transition('start => end', animate(1500)),
      transition('end => start', animate('800ms 0.5s ease-out'))
    ]), …
Run Code Online (Sandbox Code Playgroud)

animation transition angular

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

angular ×1

animation ×1

transition ×1