DHTML
What we have for you in this section.......................
SHOWING AND HIDING HTML ELEMENTS USING LAYERS
A long time back I visited a site that had a very fancy, animated navigation bar. Now, as a professional web developer, I'm not in favor of DHTML-supported, fancy navigation bars, but it was very fascinating. What they had done was, whenever you hovered your cursor over a link, a big, comics-type dialog balloon appeared to give further details of that link. I wondred how they did it, but then it slipped out of my mind.
That technique uses layers and Cascading Style Sheet definitions, and I'm going to tell you here, how it is done. Nothing pyrotechnic, but it'll pay a way to more complex tasks.
First, the demo. I believe once you visually see it, you'll understand better what I'm trying to accomplish here. Given below is a link. If you take your cursor over the link, an image appears somewhere on the screen. By tweeking you can control the placements.
Demo Area Begins
Bring Your Cursor Here and See The Image
Demo Area Ends
I've purposely made the image appear over a text area so that you don't think it is a simple rollover image effect. The image actually appears above the text.
Below lies the code that of the effect that appears above.
First the HTML part that defines the general link and the division that defines the placement of the image. Take note of the CSS defintions required to set the z-index and the "hide" attributes.
<a class="body" href="#" onmouseover="showpic('piccy');" onmouseout="hidepic('piccy')">Bring Your Cursor Here and See The Image</a>
<div style="position: relative; z-index: 1; top: -60px; left: 30px; visibility: hidden" id="piccy">
<img src="/graphics/contact.gif">
</div>
After this comes the quintessential JavaScript that actually performs the act. In between I've inserted comments using the way they are used in JavaScript, that is, using //.
<script language="javascript">
if (document.layers)
{
appear = 'show';
disappear = 'hide';
}
else if (document.all)
{
appear = 'visible';
disappear = 'hidden';
}
// Both Netscape and IE handle layers differently, and have different
// syntax for handling their behavior when it comes to handling layer
// attributes. // So whereas IE uses 'show' and 'hide,' Netscape uses 'visible' and
// 'hidden'. So we check and assign the appropriate values beforehand.
function showpic(picture)
{
var thispicture;
if (document.layers)
{
thispicture = document.layers[picture];
}
else if (document.all)
{
thispicture = document.all(picture).style;
}
thispicture.visibility=appear;
}
function hidepic(picture)
{
var thispicture;
if (document.layers)
{
thispicture = document.layers[picture];
}
else if (document.all)
{
thispicture = document.all(picture).style;
}
thispicture.visibility=disappear;
}
</script>
So this is how it works
|