[英]Animate Position Change As Div Floats Left
I have a bunch of divs that live inside a container. 我有一堆位于容器中的div。 When a user clicks on one of them they are removed and a divs below that one slide over to fill the space it left because they are set to
float:left
like this jsFiddle . 当用户单击其中的一个时,它们将被删除,并且该位置下方的div会滑过以填充其剩余的空间,因为它们被设置为
float:left
例如jsFiddle 。 I want the divs to animate as they move over to fill the space. 我希望div在移动以填充空间时进行动画处理。 Is there a CSS or jQuery function to automatically do that, or would I have to calculate the position each div is currently in and then call some kind of
animateAll()
to move them to the position that they will be? 是否有CSS或jQuery函数自动执行此操作,还是我必须计算每个div当前所在的位置,然后调用某种
animateAll()
将其移动到它们将要位于的位置?
Add $(this).addClass('hide').fadeOut(500, function() { $(this).remove(); });
添加
$(this).addClass('hide').fadeOut(500, function() { $(this).remove(); });
to hide and remove that child after transition 在过渡后隐藏和删除该孩子
demo:- 演示:-
$("div").click(function(){ $(this).addClass('hide').fadeOut(500, function() { $(this).remove(); }); });
div { float:left; height:20px; width:20px; margin:5px; -webkit-transition: all .5s ease-in-out; -moz-transition: all .5s ease-in-out; -o-transition: all .5s ease-in-out; transition: all .5s ease-in-out; } div:hover { cursor:pointer; } .hide { width: 0; height: 0; opacity: 0; margin: 0; padding: 0; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div style="background:red;"></div> <div style="background:orange;"></div> <div style="background:yellow;"></div> <div style="background:green;"></div> <div style="background:blue;"></div> <div style="background:purple;"></div>
Please check this script. 请检查此脚本。
$("div").click(function(){
$(this).css('opacity',0).animate({
width: 0,
}, 1000, function() {
$(this).remove();
});
});
try this 尝试这个
$("#divname").click(function(){
$("div").animate({"width":"0px"}, "slow",function() {
$(this).remove();
});
});
you can use jquery animate 您可以使用jQuery动画
$("div").click(function(){
$(this).remove();
$("div").animate({"left":"0px"}, "slow")
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.