简体   繁体   English

如何使用动画接连移动div

[英]How to move a div after another using animations

I'm currently moving a div from one location to another, but I want to do it with some animations. 我目前正在将div从一个位置移动到另一个位置,但是我想通过一些动画来实现。 Just have it slide to place and push the other divs down. 只是使其滑动放置并向下推其他divs How would I go about doing this? 我将如何去做呢?

Here is what I have so far. 这是我到目前为止所拥有的。

 var row = $('<div class="row">Another row inserted</div>'); $('.container').append(row); $('.button').click(function() { $('.row').addClass('row-changed'); $('.container > div:nth-child(2)').after(row); }); 
 .row { color: blue; } .row-changed { color: red; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class='container'> <button class='button'>Move</button> <div class='row'>Row here</div> <div class='row'>Row here</div> <div class='row'>Row here</div> <div class='row'>Row here</div> <div class='row'>Row here</div> </div> 

try this one 试试这个

 var row = $('<div class="row">Another row inserted</div>'); $('.container').append(row.hide().slideDown()); $('.button').click(function() { $('.row').addClass('row-changed'); var clone = row.clone().css("position", "absolute"); $('.container').append(clone); row.css("visibility", "hidden"); var sel = $('.container > div:nth-child(2)'); sel.after(row.hide().slideDown()); var position = sel.next().position(); clone.animate({ left: position.left, top: position.top }, 400, function() { clone.remove(); row.css("visibility", "visible"); }); }); 
 .row { color: blue; } .row-changed { color: red; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class='container'> <button class='button'>Move</button> <div class='row'>Row here</div> <div class='row'>Row here</div> <div class='row'>Row here</div> <div class='row'>Row here</div> <div class='row'>Row here</div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM