Forum Moderators: open
I want each navigation button to have a mouseover effect (image_on) and, when clicked, image_on should stay on while any previously clicked navigation images swap to image_off. Of course, clicking on the image should call up the appropriate page in the content frame as well.
What’s the best (most elegant) way to do this? Javascript? I spent 2 days trying to find something on the web (to cut ‘n paste) as I’m pretty JS illiterate, but didn’t find what I needed. Does anyone know where I can find something similar to pull apart?
Thanks in advance.
Here's a tutorial I found on the topic -- seems like the right approach to me. And there's enough explanation for you to customize the script to your exact situation.
[xs4all.nl...]
Anyone else know where I can find a framed web that uses image swaps similar to what I described above?
<script type="text/javascript">
// Check if it's a DOM compliant browser
var MZ = document.getElementById?true:false;
// Maybe it's an old IE?
var IE = document.all?true:false;
// Or maybe an old NN?
var NN = document.layers?true:false;var navimg = 0;
var defimg = new Array(3);
var ovrimg = new Array(3);
for(i=0; i<3; i++) {
defimg[i] = new Image;
// Default image = "images/link1.gif"
defimg[i].src = "images/link" + (i+1) + ".gif";
ovrimg[i] = new Image;
// MouseOver image = "images/link1_.gif"
ovrimg[i].src = "images/link" + (i+1) + "_.gif";
}function over(which) {
// No image switch if we're already on that page
if(navimg!= which) {
if(MZ) {
document.getElementById('img' + which).src = ovrimg[which].src;
}
else if(IE) {
document.all['img' + which].src = ovrimg[which].src;
}
else if (NN) {
document.layers['img' + which].src = ovrimg[which].src;
}}}function out(which) {
// No image switch if we're already on that page
if(navimg!= which) {
if(MZ) {
document.getElementById('img' + which).src = defimg[which].src;
}
else if(IE) {
document.all['img' + which].src = defimg[which].src;
}
else if (NN) {
document.layers['img' + which].src = defimg[which].src;
}}}function nav(which) {
navimg = which;
}
</script><a href="page1.html" onmouseover="over(1)" onmouseout="out(1)" onclick="nav(1)" target="otherframe"><img id="img1" src="images/link1.gif" width="50" height="20" border="0" alt="" /></a><br />
<a href="page2.html" onmouseover="over(2)" onmouseout="out(2)" onclick="nav(2)" target="otherframe"><img id="img2" src="images/link2.gif" width="50" height="20" border="0" alt="" /></a><br />
<a href="page3.html" onmouseover="over(3)" onmouseout="out(3)" onclick="nav(3)" target="otherframe"><img id="img3" src="images/link3.gif" width="50" height="20" border="0" alt="" /></a><br />
<style type="text/css">
a.default {
padding: 2px 10px 3px 10px;
font-size: 0.8em;
border: outset 2px #5aa0b8;
background: #004466;
color: #cccccc;
text-decoration: none;
height: 19px;
vertical-align: bottom;
}
a.default:active, a.default:focus, a.default:hover {
background: #004466;
border: inset 2px #5aa0b8;
vertical-align: middle;
color: #5aa0b8;
}
a.clicked {
padding: 2px 10px 3px 10px;
font-size: 0.8em;
border: inset 2px #5aa0b8;
background: #004466;
color: #5aa0b8;
text-decoration: none;
height: 19px;
vertical-align: middle;
}
</style><a href="page1.html" class="default" target="otherframe" onclick="document.getElementByTagName('a').className='default';this.className='clicked';">Link text</a><br />
<a href="page2.html" class="default" target="otherframe" onclick="document.getElementByTagName('a').className='default';this.className='clicked';">Link text</a><br />
<a href="page3.html" class="default" target="otherframe" onclick="document.getElementByTagName('a').className='default';this.className='clicked';">Link text</a><br />
Personally I prefer the CSS way ;)
• Page loads faster
• Easy to change the link text
• Buttons are dynamic (they automatically resize to fit the text)
If you don't want them to be dynamic you can always specify the
width, and set text-align to center.
I really appreciate it DD particularly since I spent days trying to piece together bits and pieces from all over.. to no avail.
John, thanks for the tip re ranking frames. I have put a little js in each page to stop it from becoming an orphan just in case it gets picked up. (its so sad when that happens :()
We are not excluding it from the SEngs completely, but are not promoting it either; the people who need to know it's there, do... and if others stumble upon it, so be it.)
Thanks all, much obliged.