Quote:
Originally Posted by corybarnes
Here's an added twist...is it possible to add a text caption below each large image, and have those captions change when the image is changed?
|
Yeah. If you add a p element with an ID, say "description" you can add something like this:
Code:
document.getElementById('description').textContent = "descriptive text";
My only concern is that I think IE6 and below doesn't support textContent, but I'm not sure. Then you'd need to determine the user agent and then use textContent or innerText (I belive this was the IE only property).
Now to make this compatible with the script you already have you don't need to do all too much.
Code:
function replaceImg(path,desc) {
var imgDest = document.getElementById('image');
var imgSrc = path;
imgDest.setAttribute("src", imgSrc);
document.getElementById('description').textContent = desc;
}
And then whenever you call it, use something like this inside of you img tag:
Code:
onmouseover=replaceImg('img002_image.jpg','In this image there is nothing');
Of course to make it a bit more beautiful, well I think it would be more beautiful, if you created an array inside of your JS that has all your descriptions stored and then just passed the number of which description to use... a switch statememnt could do that, or you could actually use the filename as well. Which is the ebst Ic annot say, do what works for you.
__________________
George Bush would never take me alive.
|