说的是对于两层嵌套,高度都不确定 ,内容有待优化,最近又遇到了此类问题,就是对于高度不确定,想要使用transition,使元素有过渡效果,方法主要就是 使用的 scrollHeight, 然后通过js设置元素高度;
代码:
<div class="shortcut"></div>
<el-button @click="changeUpDown">按钮</el-button>
changeUpDown() {
var el = document.querySelector('.shortcut');
var height = el.scrollHeight;
if(!this.upDown){
el.style.setProperty('height', height + 'px');
} else {
el.style.setProperty('height', 282 + 'px'); // 这里我的默认高度 282px
}
},
.shortcut {
transition: all 1s;
height: 282px;
overflow: hidden;
}