您可以使用轉換來完成這種事情。所以元素位置的變化會在1秒內變換,或者您想要的時間變長。
示例:2個框,Box1和Box2。在點擊框2,我們希望它收縮,移動框1
HTML:
<div class="container">
<div class="box box1"></div>
<div class="box box2"></div>
</div>
CSS:
.container {
position: relative;
}
.box {
background: #333;
border:1px solid #fff
}
.box1 {
transition:all 1s;
position: absolute;
top:0px;
left:500px;
height: 20px;
width: 20px;
}
.box2 {
position: absolute;
top:100px;
left:0px;
height: 100px;
width: 100px;
}
的Javascript(jQuery的)
$('.box2').click(function(){
$(this).removeClass('box2');
$(this).addClass('box1');
});
DEMO:https://jsfiddle.net/33m3t16d/1/
希望這有助於隊友。
動態? __ –