【问题标题】:Div is expanding instantly instead of over time?Div 是立即扩展而不是随着时间的推移?
【发布时间】:2019-05-07 05:59:48
【问题描述】:

我的 div 在单击我的触发器后立即扩展,而不是随着时间的推移发生...这是为什么,我该如何解决?

html

<div class="card" #panel [ngClass]="{heightChange: panel.isExpanded}">
  <div class="header">
    <div class="itemName">Some text goes here</div>
    <mat-icon *ngIf="!panel.isExpanded" (click)="panel.isExpanded=true">edit</mat-icon>
    <mat-icon *ngIf="panel.isExpanded" (click)="panel.isExpanded=false">cancel</mat-icon>
  </div>
</div>

css

div.card {
  background: white;
  padding: 12px;
  justify-items: center;
  transition: all 0.5s;
}

mat-icon {
  cursor: pointer;
}

div.header {
  display: flex;
  justify-content: space-between;
}

.heightChange {
  height: 150px;
}

stackblitz

【问题讨论】:

  • 您无法从auto 转换为设定的号码。您需要定义开始和结束高度。

标签: html css angular animation angular-material


【解决方案1】:

只需将height 属性添加到您的div.card 类中即可获得初始高度。

然后添加另一个名为div.card.heightChange 的具有新高度的类。 transition 仅适用于 height 而不是全部。

将您的 CSS 类更改为:

div.card {
  background: white;
  padding: 12px;
  height: 25px;
  justify-items: center;
  transition: height 0.5s;
}

div.card.heightChange {
  height: 150px;
}

这里有一个Working Sample StackBlitz 供您参考。

【讨论】:

  • 我在之前的尝试中做过,但没有成功。感谢您的闪电战:-)
猜你喜欢
  • 2022-01-09
  • 2017-11-10
  • 2018-03-23
  • 1970-01-01
  • 1970-01-01
  • 2014-02-04
  • 2014-12-02
  • 2021-07-22
  • 1970-01-01
相关资源
最近更新 更多