collapsable side bar (IE)

J

J

Hello,

I'd like to create sections that are collapsible via clicking on a
graphic next to (or above) the section (e.g. collapsible cells of a table)

I've given both the graphic and the section an ID property and I have
written this:

function hideShow (name1)
{
if (document.all(name1).style.display == "none")
document.all(name1).style.display = "inline"
else
document.all(name1).style.display = "none"
}

which seems to work, but how can I pass in the image ID and have the
image swapped each time I collapse/expand the section?

any help appreciated,
BK.
 
F

FunGuySF

The simple answer is, provide a name in the image tag, then:

document.images[imagename].src = "img/image1.jpg";

However, when creating an image swap, you should consider precashing the
images, so the user doesn't get bogged down with a delay (ugly visual
stuff).

To name the image tag:

<img id="image1" border="0" src="img/image1.jpg" />

To precash the images:

var cachedImg = new Object( );
cachedImg['image1'] = new Image();
cachedImg['image1'].src = "img/image2.jpg";

then, when you do the swap:

document.images['image1'].src = cachedImg['image1'].src

That'll do the trick!
 
R

Richard

I'd like to create sections that are collapsible via clicking on a
graphic next to (or above) the section (e.g. collapsible cells of a
table)
I've given both the graphic and the section an ID property and I have
written this:
function hideShow (name1)
{
if (document.all(name1).style.display == "none")
document.all(name1).style.display = "inline"
else
document.all(name1).style.display = "none"
}
which seems to work, but how can I pass in the image ID and have the
image swapped each time I collapse/expand the section?
any help appreciated,
BK.


DYnamicdrive.com has a menu called "switch menu" which does what you want.
You can see it in action at my site www.somestuff.batcave.net/
You're close though.
Take a look at their source code to see what they did.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Thu, 13
Jan 2005 22:18:00, seen in J
function hideShow (name1)
{
if (document.all(name1).style.display == "none")
document.all(name1).style.display = "inline"
else
document.all(name1).style.display = "none"
}


function hideShow (name1) { var T = document.all(name1).style
T.display = (T.display == "none") ? "inline" : "none" }

function hideShow (name1) { with (document.all(name1).style)
display = (display == "none") ? "inline" : "none" }

should be more economical equivalents.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top