Reputation: 1665
When I click on the green div, everything hides, but the green div is jerky, as in, it comes right next to the first green div with a jerky motion. Is it possible to smooth transit, so that it slides and takes its places right next to the first green div?
JS:
$('.green').click(function(){
$('.others').fadeOut();
});
CSS:
.green{ background:green; padding:10px; margin:10px; }
.red{ background:red; padding:10px; margin:10px; }
.blue{ background:blue; padding:10px; margin:10px; }
.green:hover{ cursor:pointer;}
.fade{display:none; opacity:0;}
div{ float:left; }
HTML:
<div class="green"></div>
<div class="red others"></div>
<div class="blue others"></div>
<div class="green"></div>
<div class="red others"></div>
<div class="blue others"></div>
Upvotes: 8
Views: 4769
Reputation: 6050
You can try this:
$('.green').click(function(){
$('.others').fadeOut("slow");
});
OR
this:$('.green').click(function(){ $('.others').hide("literal"); });
Upvotes: 0
Reputation: 4199
The trick is to remove opacity & size, then hide it.
$('.green').click(function(){
$('.others').animate({'opacity':0},200,function(){
$(this).animate({'width':0},200,function(){
$(this).hide();
});
});
});
If you divs are below each other you can animate height
to zero(0)
.
Upvotes: 1
Reputation: 151
$('.green').click(function(){
$('.others').animate({
"margin-left":0,
"margin-right":0,
"padding-left":0,
"padding-right":0,
width:0,
}, 300);
});
Do animation, clear just margins and paddings, and animate width to 0, so adjecent divs move along
Upvotes: 1