An exercise in collapsing and expanding a “menu” when the title is clicked. Made for Flash Experiments portal.
The entire thing is accessible in that if JavaScript is turned off, the menu or list is still displayed. It just might push down everything else if the list is too long.
15 Feb 2008.
Not too complicated.
Here’s the code. Please link back here if you’re using it.
Put this JS in the head tag.
function doIt(){
var menu=document.getElementById("menu"); //makes variable for the list
menu.style.display="none"; //hide the list
var listSwitch=false; //false means the list is hidden;
var menuTitle=document.getElementById("menuTitle"); //makes variable for the title
menuTitle.onmouseover=menuTitle.style.cursor="pointer";
function expandCollapseList(){
if (listSwitch==false){ //if the switch is "off"
menu.style.display="block"; //show list
listSwitch=true; //switch becomes "on"
}
else if(listSwitch==true){
menu.style.display="none"; //hide list
listSwitch=false; //now the list is hidden, which makes it false;
}
}
menuTitle.onclick=expandCollapseList;
}
onload=doIt;
Put this HTML in the body tag.
<p id='menuTitle' >Click here to open/close menu</p>
<ul id='menu' >
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>