Here is jsfiddle !
I am trying to make user page where he can switch between pages by clicking on div’s. Problem is, I will need more then 3 div’s , and this already is very messy…
<div id="dviOverdivWraper">
<div class="containterBox">
<div id="leftOver" style="background-color:blue">
</div>
<div id="rightOver" style="background-color:red">
</div>
<div id="thirdOver" style="background-color:yellow">
</div>
</div>
</div>
#dviOverdivWraper {
width: 800px;
height: 400px;
margin: 0px auto;
top: 200px;
text-align:center;
}
#dviOverdivWraper .containerBox{
width: 800px;
height: 400px;
margin: 0px auto;
text-align:center;
}
#leftOver{
width: 400px;
height: 200px;
float: left;
}
#rightOver, #thirdOver{
width: 50px;
height: 200px;
float: left;
}
$("#rightOver").click(function () {
$("#leftOver").animate({
width: "50px"
}, 500, null);
$("#rightOver").animate({
width: "400px"
}, 500, null);
$("#thirdOver").animate({
width: "50px"
}, 500, null);
});
$("#leftOver").click(function () {
$("#rightOver").animate({
width: "50px"
}, 500, null);
$("#leftOver").animate({
width: "400px"
}, 500, null);
$("#thirdOver").animate({
width: "50px"
}, 500, null);
});
$("#thirdOver").click(function () {
$("#rightOver").animate({
width: "50px"
}, 500, null);
$("#leftOver").animate({
width: "50px"
}, 500, null);
$("#thirdOver").animate({
width: "400px"
}, 500, null);
});
How can I optimize it, because I will need more then 3 div’s?
jsFiddle DEMO
P.S: I just added a class
.boxto your elements.