Reputation: 73
I am working on JavaScript and jQuery, and my question is related to div
s in an HTML page. Given that I am using 2 div
s in an HTML page, is there any option to reduce the size of one div
and expand the size of another using onclick
event. I have a fiddle here which has a div
overlapping the other div when clicked.
Here is my code:
$(function() {
var expanded = false;
$('#sidebar').click(function() {
if (!expanded) {
$(this).animate({'left' : '70px'}, {duration : 400});
expanded = true;
}
else {
$(this).animate({'left' : '565px'}, {duration: 400});
expanded = false;
}
});
});
Upvotes: 0
Views: 1142
Reputation: 775
in below demo we can add n number of div children "mainContainer" div Please check DEMO
http://jsfiddle.net/mahesh2524/RqJt7/6/
<div id="mainContainer">
<div id="steam"></div>
<div id="sidebar" class="sidebar"></div>
<div id="sidebar2" class="sidebar"></div>
Upvotes: 0
Reputation: 1004
You can use below code to do slidedown and slideup in onclick event
$(function()
{
var expanded = false;
$('#flip').click(function(){
$("#panel").slideToggle("slow");
});
})
Take a look at the working sample at jqfaq.com
Upvotes: 1
Reputation: 7380
If you want vice versa, pls check DEMO http://jsfiddle.net/yeyene/3DpfJ/47/
$('#sidebar').click(function(){
$(this).animate({width:'100px'}, 400);
$('#steam').animate({width:'500px'}, 400);
});
$('#steam').click(function(){
$(this).animate({width:'100px'}, 400);
$('#sidebar').animate({width:'500px'}, 400);
});
Upvotes: 0
Reputation: 606
try this one, http://jsfiddle.net/markipe/3DpfJ/45/
$(function(){
var expanded = false;
$('#sidebar').click(function(){
if (!expanded)
{
$('#sidebar').animate({width:'69%'}, 400);
$('#steam').animate({width:'29%'}, 400);
expanded = true;
}
else
{
$('#sidebar').animate({width:'29%'}, 400);
$('#steam').animate({width:'69%'}, 400);
expanded = false;
}
});
});
Upvotes: 0