0
我想要一類已被應用後,動畫元素的高度,這裏的簡化代碼:CSS3動畫無法按預期工作
HTML
<div class="section">
<div class="panel">
<a href="#" class="toggle">Click</a>
<div class="panel-content">
Some content...
</div>
</div>
</div>
CSS
.section {
position: relative;
width: 500px;
height: 200px;
margin: 100px auto;
background: #ccc;
}
.panel {
width: 65%;
position: absolute;
left: 0;
bottom: 0;
}
.toggle {
display: inline-block;
height: 15px;
background: #ddd;
}
.panel-content {
max-height: 0;
overflow: hidden;
transition: max-height 1s;
}
.active .panel-content {
max-height: 9999px;
}
JS
當我點擊.toggle
鏈接active
類.panel
元素設置爲.panel-content
高度的動畫,但是當第一次添加類時,內容顯示沒有動畫,當它被刪除時,元素需要一秒(轉換的持續時間)到開始動畫。你可以看到現場演示在這裏:http://codepen.io/javiervd/pen/bLhBa
我試圖與位置和溢流性能,以及玩,但我不能讓它工作,也許有達到同樣的效果另一種方式?
在此先感謝。
此。完美的答案。 –
我做的活動類添加到我的'.panel'元素,使過渡發生,我只是ommitted爲簡潔,但它在我張貼,我雖然更新我使用JavaScript答案codepen。 – javiervd