Creating an image button that reflects the state of the animated DIV it corresponds to (ie: "up.gif" by default, but change to "down.gif" when the DIV is sliding down) is quite simple. Basically, inside animatedcollapse.js, add the two lines in red to the below function:
Code:
animatedcollapse.prototype.slideit=function(){
var slidetype=(isNaN(this.contentheight))? "n/a" : parseInt(this.divObj.style.height)==0? "down" : "up"
if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
alert("Please wait until document has fully loaded then click again")
else if (parseInt(this.divObj.style.height)==0)
this.slidedown()
else if (parseInt(this.divObj.style.height)==this.contentheight)
this.slideup()
return slidetype
}
This gets the "slideit()" function to return a string indicating whether the DIV is currently sliding up, down, or none of the above.
Then, using demo #2 within the code of Step 2 you pasted, your image button may look something like this:
Code:
<p><b>Example 2:</b></p>
<script type="text/javascript">
function collapsebutton(animatedvar, imgid, downimg, upimg){
var imgref=document.getElementById(imgid)
var slidestatus=animatedvar.slideit()
if (slidestatus=="n/a" || slidestatus=="up")
imgref.src=upimg
else
imgref.src=downimg
return false
}
</script>
<a href="#" onClick="return collapsebutton(collapse2, 'mybutton', 'down.png', 'up.png')"><img id="mybutton" src="up.png" border="0" /></a>
<div id="cat" style="width: 300px; background-color: #99E0FB;">
<!--Your DIV content as follows. Note to add CSS padding or margins, do it inside a DIV within the Collapsible DIV -->
<div style="padding: 0 5px">
<h3>Content inside DIV!</h3>
<h3>Content inside DIV!</h3>
<h4>Note: No CSS height attribute defined. Persistence enabled.</h4>
</div>
</div>
<script type="text/javascript">
//Syntax: var uniquevar=new animatedcollapse("DIV_id", animatetime_milisec, enablepersist(true/fase), [initialstate] )
var collapse2=new animatedcollapse("cat", 800, true)
</script>
Again, the code in red is new. The HTML for the button itself looks something like:
Code:
<a href="#" onClick="return collapsebutton(collapse2, 'mybutton', 'down.png', 'up.png')"><img id="mybutton" src="up.png" border="0" /></a>
Where the 1st param would be the variable of the animated DIV instance, the 2nd param the ID of the IMG element for the button, the 3rd and 4th params, the paths to the two images.
Regarding part 2 of your 1st question, it seems you're looking to get a particular DIV to expand based on information passed via the URL. This thread might help: http://www.dynamicdrive.com/forums/s...ad.php?t=24920
For question #2, currently each animated collapse DIV operates completely separate from the next on the page, so there's no way one instance can probe the status of another. Future update to this script should change that.
Bookmarks