【发布时间】:2015-01-17 07:29:50
【问题描述】:
所以我怀疑 CSS3 过渡不是解决此问题的方法,但这是我想要完成的:
在包装器/子 div 场景中,子 div 被换成了一个不同的、未知高度的 div。这会导致突然的高度变化。我希望高度变化能够平滑过渡,就像 CSS3 属性过渡一样。
这是垃圾箱: http://jsbin.com/hakanulodo/9/edit
为了解决链接失效问题,这里是 bin 的初始代码:
# HTML
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div class="wrapper">
<div class="child">
Original
</div>
</div>
<div class="new">
New
</div>
</body>
</html>
# css
.wrapper {
transition: height 0.25s ease 0.2s;
}
.child {
height: 100px;
width: 100px;
line-height: 100px;
text-align: center;
background: purple;
color: white;
}
.new {
display: none;
height: 200px;
width: 100px;
line-height: 100px;
text-align: center;
background: blue;
color: white;
}
# javascript
$('.wrapper').click( function() {
var item = $('.new').css("display", "block");
$('.wrapper').html(item);
});
我对 JS 解决方案和 CSS 持开放态度。提前致谢!
【问题讨论】:
标签: javascript jquery css