Greetings from Germany!
Why should you need JavaScript for the effect of the second example? In my opinion this could also be achieved by a purely CSS-based solution! In addition I'd provide basic funtionality even if JavaScript is turned off. This leads me to the following ideas:
* Use an IFrame to display the texts and put them into extra HTML files
* Use a target attribute inside the hyperlinks to make the IFrame load the texts
* Use a transitional doctype (required - and already in use by your examples)
* Use CSS to swap the images
I'm thinking along the lines of something like this:
HTML Code:
<p><img src="kitchen.gif" alt="" id="kitchen" />
<!-- here go the several links... just one as an example now -->
<a href="adams_story.html" target="grey_box" onclick="return showText(this)">
<img src="heinz.gif" alt="" id="adam" />
<img src="adam.gif" alt="Adam's Story" class="swap" />
</a>
<p>
<iframe src="" name="grey_box" id="grey_box" />
Now the second image inside the link can be made display:none as default and can be made visible on hovering the link:
Code:
#adam { /* ketchup bottle */
display: block;
position: absolute;
left: 260px;
top: 40px;
}
a .swap { /* any explanatory text image */
display: none;
position: absolute;
z-index: 2; /* must overlap a permanently displayed image */
top: 319px;
left: 75px;
}
a:hover .swap { /* any visible explanatory text image */
display: block;
}
This way the second image will disappear on moving the mouse away from the link and won't stay if the link has been focussed. The function "showText(this)" can now display the swapped image permanently according to the displayed text. It needs a reference to the <a> Element in order to not display the text prior to its "closing" animation and to make the swap image to now show permanently. Look at this:
Code:
// THIS CODE HAS NOT BEEN TESTED!!!
function showText (linkElement) {
// get all swap images and hide them (again)
var a = document.getElementsByTagName("a"), i, imgs;
for (i = 0; i < a.length; i++) {
imgs = a[i].getElementsByTagName("img");
if (imgs[1] && imgs[1].className == "swap") {
imgs[1].style.zIndex = "";
imgs[1].style.display = "";
}
}
// animate_box("close"); // replace this with your functionality
document.getElementById("grey_box").src = linkElement.href; // load text into iframe
// animate_box("re-open"); // replace this with your functionality
i = linkElement.getElementsByTagName("img")[1]; // permanently show swap image
i.style.display = "block";
i.style.zIndex = "1";
return false; // prevent original browser reaction on clicking a link
}
Mind that in some cases I have used IDs rather than classes. Whenever something can't occur more than once on a page using an ID seems more suitable to me than using a class. This of course affects some syntax in your CSS code.
Hope this helps a bit...
Felix Riesterer.
Bookmarks