简体   繁体   English

默认状态下没有角度动画

[英]No Angular Animations on the default state

Hi here is my updated code which has animations of sliding left and right. 嗨,这里是我更新的代码 ,其中包含左右滑动动画。 So I wanted to see if we can control the default state without any animations. 所以我想看看我们是否可以在没有任何动画的情况下控制默认状态。 Like there shouldn't be any animation when panel is 'TRUE' and when we click the button the animations should work as usual. 就像当面板为“TRUE”时不应该有任何动画,当我们点击按钮时,动画应该像往常一样工作。

I am now able to control the default state of the slider but the button needs to be still looked into. 我现在能够控制滑块的默认状态,但仍需要查看按钮。

Also, I have added the same code for the button too. 另外,我也为按钮添加了相同的代码。 And it won't work for the button. 它不适用于按钮。 If we use the commented code for the button it works but again there is animation on the first time which I don't want. 如果我们使用按钮的注释代码它可以工作但是第一次有动画我不想要。

You can disable animations with [@.disabled]="true" Source: https://angular.io/api/animations/trigger#disabling-animations 您可以使用[@.disabled]="true"禁用动画来源: https[@.disabled]="true"

Sample: 样品:

<div class="container" [@slide]="isOpen ? true : false" [@.disabled]="true">

Will disable the sliding animation of the gray box. 将禁用灰色框的滑动动画。

Ok! 好! so here it is, found a solution to control the button state as well on the page load. 所以在这里,找到了一个解决方案来控制按钮状态以及页面加载。

isOpenEver = false;

  get openCloseState(): string|undefined{
    if(!this.isOpenEver){
      return undefined;
    }
    return this.isOpen ? 'open' : 'closed';
  }

togglePanel(): void {
    this.isOpenEver = true;
    this.isOpen = !this.isOpen;
  }

And using the state in the HTML button: 并使用HTML按钮中的状态:

<button [class.button-resize-expand]="!isOpen"
          [class.button-resize-collapse]="isOpen"
          (click)="togglePanel()" [@openClose] ="openCloseState">
    <mat-icon class="rotate-chevron" [class.rotate-clicked]="!isOpen">{{isOpen ? 'chevron_left' : 'chevron_right'}}</mat-icon>
  </button>

Also here is the updated stackblitz 这里还有更新的stackblitz

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM