Reputation: 131
So i have a few different divs id'ed "sstroke" "pixel" "bstroke" "inside" "textbox" "text" and "piccars". My code is the following :
$(document).ready(function(){
$("img#buttoncar").click(function(){
$("div#sstroke").animate({width:168},300,"linear",function(){
$("div#pixel").animate({width:28},150,"linear",function(){
$("div#bstroke").animate({width:1000},1300,"linear",function(){
$("div#inside").animate({height:450},700);
$("div#textbox").animate({height:435},700,function(){
$("#text").delay(500).animate({opacity:1},2000);
$("#piccars").delay(500).animate({opacity:1},2000);
});
});
});
});
});
});
My aim is to get them to go back to their original state on another click of the "buttoncar" (button that originally unleashes the fury of all those elements deploying) or on the click of another button (that does the same thing with other divs), in the order opposite to how they deployed (i.e. starting with "piccars", then "text", all the way back to "sstroke").
I tried wrinting the same the opposite way, but it just deployed and right after folded back, i tried the .toogle() thingy but it was doing something weird (deploying diagonally instead of horizontally or vertically).
Anyone has a solution? I am very stuck..
Update: here is the jsFiddle : http://jsfiddle.net/TSEJP/
Upvotes: 1
Views: 1575
Reputation: 131
After a few hours of trying out (i'm not that good..), i found a solution that fits my needs, and that will hopefully help other programmers! Here goes! The trick was to use 4 different scripts (i didn't get to the part of re-clicking the same button and folding everything back upon that action, but still..).
Let's summarize what we have :
so here we go :
>$(document).ready(function(){
$("#b1").click(function(){
$("#div11").animate({width:100},500,"linear",function(){
$("#div12").animate({width:150},750,"linear",function(){
$("#div13").animate({height:200},1000,linear,function(){
});
});
});
});
});
$(document).ready(function(){
$("#b2").click(function(){
$("#div21").animate({width:100},500,"linear",function(){
$("#div22").animate({width:150},750,"linear",function(){
$("#div23").animate({height:200},1000,linear,function(){
});
});
});
});
});
$(document).ready(function(){
$("#b2").click(function(){
$("#div23").animate({width:0},500,"linear",function(){
$("#div22").animate({width:0},375,"linear",function(){
$("#div21").animate({height:0},275,linear,function(){
});
});
});
});
});
$(document).ready(function(){
$("#b1").click(function(){
$("#div13").animate({width:0},500,"linear",function(){
$("#div12").animate({width:0},375,"linear",function(){
$("#div11").animate({height:0},275,linear,function(){
});
});
});
});
});
<html>
<head>
<link rel="shortcut icon" href="images/rocherico.ico"/>
<title>fold-unfold</title>
<link rel="stylesheet" type="text/css" href="css/fold-unfold.css"/>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript" src="scripts/script1.js"></script>
<script type="text/javascript" src="scripts/script2.js"></script>
<script type="text/javascript" src="scripts/script3.js"></script>
<script type="text/javascript" src="scripts/script4.js"></script>
</head>
<body>
<div id="div11"></div>
<div id="div12"></div>
<div id="div13"></div>
<div id="div21"></div>
<div id="div22"></div>
<div id="div23"></div>
</body>
</html>
#div11 {background:"red";height:100px;width:0px;position:absolute;top:10px;left:100px}
#div12 {background:"red";height:130px;width:0px;position:absolute;top:10px;left:200px}
#div13 {background:"red";height:70px;width:0px;position:absolute;top:10px;left:350px}
#div21 {background:"blue";height:100px;width:0px;position:absolute;top:250px;left:100px}
#div22 {background:"blue";height:130px;width:0px;position:absolute;top:250px;left:200px}
#div23 {background:"blue";height:70px;width:0px;position:absolute;top:250px;left:350px}
And there we go : folding/unfolding 1 click away!
adapt to whatever need (animate the height, the position, etc.) your website requires!
Cheers for those who helped!
Upvotes: 1
Reputation: 9964
I think this is what you are looking for. I hope this can help you or give you a hint to proceed :)
There is Go Back button which restore the position of all div's
http://jsfiddle.net/ipsjolly/RhsgR/1/
UPDATED WITH ANIMATION :P
http://jsfiddle.net/ipsjolly/RhsgR/2/
Upvotes: 1