[英]Make height of div container smaller when nested divs slide out
每当尝试单击时div.container内部的div滑出时,我都试图使div.container的高度变小,但div的高度仍保持相同的高度。
我还希望尚未单击的div滑入已单击的div的位置。
这是我的JSFiddle: https ://jsfiddle.net/ispykenny/soysd2zu/任何帮助都将非常有帮助! 谢谢! 这是代码。
<div class="container">
<div class="two"><p>slide over on click</p></div>
<div class="three"><p>slide over on click</p></div>
<div class="two"><p>slide over on click</p></div>
<div class="three"><p>slide over on click</p></div>
<div class="two"><p>slide over on click</p></div>
<div class="three"><p>slide over on click</p></div>
<div class="two"><p>slide over on click</p></div>
<div class="three"><p>slide over on click</p></div>
<div class="two"><p>slide over on click</p></div>
<div class="three"><p>slide over on click</p></div>
.container{
background-color:green;
}
.two{
width:300px;
margin-left:auto;
margin-right:auto;
cursor:pointer;
background:#666;
text-align:center;
padding:10px;
font-size:10px;
border:1px solid black;
position:relative;
}
.three{
width:300px;
margin-left:auto;
margin-right:auto;
cursor:pointer;
background:#666;
text-align:center;
padding:10px;
font-size:10px;
border:1px solid black;
position:relative;
}
$(document).ready(function(){
$('.two').click(function(){
$(this).animate({right:"1500px"},'5000');
});
$('.three').click(function(){
$(this).animate({left:"1500px"},'5000');
});
});
好像您需要在动画完成后对单击的div进行样式“显示”以将其设置为“无”。 但是通过这种方式,在那个空旷的领域不会有任何消失的动画。
$(document).ready(function(){
$('.two').click(function(){
$(this).animate({right:"1500px"},'5000', function() {
$(this).css("display", "none")
});
$('.three').click(function(){
$(this).animate({left:"1500px"},'5000', function() {
$(this).css("display", "none")
});
});
使用slideUp平滑移动其余块。
$(document).ready(function () {
$('.two').click(function () {
$(this).animate({
right: "1500px"
}, '5000', function() { $(this).slideUp(); });
});
$('.three').click(function () {
$(this).animate({
left: "1500px"
}, '5000', function() { $(this).slideUp(); });
});
});
https://jsfiddle.net/mblenton/soysd2zu/3/
$(document).ready(function () {
$( '.two' ).click(function() {
$( this).animate({
right: "1500px"
}, 1000, function() {
$(this).remove();
});
});
$( '.three' ).click(function() {
$( this).animate({
left: "1500px"
}, 1000, function() {
$(this).remove();
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.