【发布时间】:2013-07-01 14:14:45
【问题描述】:
问题:我能否使用 CSS 过渡来控制一个 div 如何移动到另一个被隐藏的 div 创建的空出空间中。
我的应用中有元素根据用户设置的时间间隔出现和消失(显示:无)。正如 display:none 所期望的那样,有时相邻的元素会移动以占据由 . 腾出的空间。
我不介意在这种情况下移动。我想控制它的移动方式。我想要的是通过 css 转换或其他方法移动,而不仅仅是混蛋到位。这可能吗?
这是一个 JS fiddle,通过按钮单击来说明场景。当#red 被隐藏时,我希望看到#blue 逐渐移动到位。谢谢。
这是 jsfiddle 中的代码:
HTML
<div id="red"></div>
<div id="blue"></div>
<p>
<button id="remove" type="button">Remove Red</button>
CSS
#red {
display: inline-block;
background-color: red;
height: 200px;
width: 200px;
}
#blue {
display: inline-block;
background-color: blue;
height: 200px;
width: 200px;
}
Javascript
$("#remove").on("click", function(event){
if($('#remove').text()=="Remove Red") {
$('#red').fadeOut();
$('#remove').html("Restore Red");
}else {
$('#red').fadeIn();
$('#remove').html("Remove Red");
}
});
【问题讨论】:
-
你研究过 jQuery 效果吗? jqueryui.com/effect
-
谢谢,但我试图避免添加 jquery UI,因为我知道它与 Bootstrap 相处得不太好。希望有一个纯 CSS 的解决方案。
-
你可以在没有 jQuery UI 的情况下做到这一点。试试看这个帖子:stackoverflow.com/questions/14934336/…
标签: html css css-transitions css-animations