I have the following script which grabs all images in a div with id "right" and attaches "_mo" (+ suffix) to them on mouseover. These images are navigation thumbs that each link to a page which has the full version of the image (see for instance this page). The following works fine:
However, I would like to extend it so that if a user is on a page that corresponds to the "active" thumb, that thumbnail-image has the "_mo" attached by default. I understand I'd have to give the "active" thumbnail an id of, say, "current" and then use the DOM to access it -- but that's where the trouble starts...Code:var W3CDOM = (document.createElement && document.getElementsByTagName); var mouseOvers = new Array(); var mouseOuts = new Array(); window.onload = init; function init() { if (!W3CDOM) return; var nav = document.getElementById('right'); var imgs = nav.getElementsByTagName('img'); for (var i=0;i<imgs.length;i++) { imgs[i].onmouseover = mouseGoesOver; imgs[i].onmouseout = mouseGoesOut; var suffix = imgs[i].src.substring(imgs[i].src.lastIndexOf('.')); mouseOuts[i] = new Image(); mouseOuts[i].src = imgs[i].src; mouseOvers[i] = new Image(); mouseOvers[i].src = imgs[i].src.substring(0,imgs[i].src.lastIndexOf('.')) + "_mo" + suffix; imgs[i].number = i; } } function mouseGoesOver() { this.src = mouseOvers[this.number].src; } function mouseGoesOut() { this.src = mouseOuts[this.number].src; }
Thanks for any help!





Bookmarks