Jump to content

Showlayer And/or Changing Z-index


kate
 Share

Recommended Posts

Hello all, Popping up from lurker-ville to ask if anyone could give me a hand. I'm trying to show a layer and hide others onClick but i can't seem to make it work :) I've used pretty much the same script elsewhere and it's ok but this is making errors like bunnies at the moment. Any other suggestions on how to do this would also be welcome. All help huuugely appreciated. thanks muchly, Kate xThis is my code at the moment (js nicked from www.jessett.com):HTML: has this in<tr><td><a href="#home" OnClick = "hideAll(); showLayer('layer1'); return false;">page 1</a></td><td><a href="#REL" OnClick = "hideAll(); showLayer('layer2'); return false;">page 2</a></td><td><a href="#EA" OnClick = "hideAll(); showLayer('layer3'); return false;">page 3</a></td></tr>then layer contents defined.</html>css file with element properties in. All 3 layers intial visibility:hidden.</css>JS:function showLayer(layerName){ if(check){ if (what =="none"){ return; } else if (what == "moz"){ document.getElementById(layerName).style.visibility="visible"; } else{ eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"'); } } else {// alert ("Please wait for the page to finish loading."); return;} } function hideLayer(layerName){ if(check){ if (what =="none"){ return; } else if (what == "moz"){ document.getElementById(layerName).style.visibility="hidden"; } else{ eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"'); } } else {// alert ("Please wait for the page to finish loading."); return;} } function hideAll(){ hideLayer('layer1'); hideLayer('layer2'); hideLayer('layer3'); hideLayer('layer4'); hideLayer('layer5'); hideLayer('layer6'); }

Link to comment
Share on other sites

1. I do not see values for check and what. Could be your script reaches check and simply terminates.2. Good news is you don't need them. This script must be 10 years old or more. document.getElementById() has been available in ALL browsers for a LONG time. There is no need to go browser sniffing to find a work-around.3. (FWIW, the browser-sniffing technique this thing seems to expect is terrible. It is better to test for functionality than for browser-names, since browsers evolve and usually acquire the functionality in later versions.)4. So the whole showLayer function can simply be this:document.getElementById(layerName).style.visibility="visible";and hideLayer can be reduced to this:document.getElementById(layerName).style.visibility="hidden";

Edited by Deirdre's Dad
Link to comment
Share on other sites

Ooh thanks for the quick reply! I did have a feeling the site I got it from was quite old but the basic html info there was quite useful :)Sorry I didn't put the whole script in earlier check and what were defined further up, but I now have a much more streamlined script thanks to you! I think the problem was with the hideAll function, which was hiding 6 layer where I only had 3 layers in the rest of the code :S seems to be working now.Thanks again for your help, will almost definitely be back shortly for more :) In case I've not mentioned, this site is *awesome* Kxx

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...