css - Div css 过渡不会在切换时折叠

标签 css angular animation

我想切换此 div 以在单击时展开和折叠。展开的过渡有效,但是我不知道如何过渡折叠。我想使用 max-height 以便在我的 div 中包含动态(大或小)内容。

div.component.html

<div
[ngClass]="{'expand': divClass, 'collapse': !divClass}"
(click)="divClass = !divClass"
class="a">
</div>

div.component.css

.a {
    width: 400px;
    height: 100px;
    max-height: 100px;
    transition: max-height 1s;
}

.expand {
    background-color: red;
    height: 500px;
    max-height: 500px;
}

.collapse {
    background-color: red;
    max-height: 100px;
    height: 100px;
    transition: max-height 1s;
}

最佳答案

我只是将过渡更改为 transition-duration..just css 的东西

div.component.css

.a {
    width: 400px;
    height: 100px;
    max-height: 100px;
    transition-duration: 1s;
}

.expand {
    background-color: red;
    height: 500px;
    max-height: 500px;
}

.collapse {
    background-color: red;
    max-height: 100px;
    height: 100px;
    transition-duration: 1s;
}

这里是 DemoStackBlitz我 fork 显示它工作

关于css - Div css 过渡不会在切换时折叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50162283/

相关文章:

html - 有谁知道 Flickr 使用的 HTML 实体作为操作菜单中的箭头?

Angular 6 生产版本 "Can' t 绑定(bind)到 'disabled',因为它不是 'div' 的已知属性”

css - svg 中的 3d 按钮动画

angular - ngif 导致页面重新加载 - Angular 2

java - Android 动画无法正常工作

ios - 现代时代 UITableView 动画

html - 使用嵌套 DIV 时如何从 IE 获得所需的 z-index 行为?

css - 你如何找到百分比宽度的实际像素宽度

应用于 DIV 内容的 CSS

javascript - Angular 2 - 在硬编码默认值时在下拉列表中设置默认值