Tuesday, May 12, 2009

JavaScript: Toggle Visibility Script 2

<html><head><title>link box</title>
<style>
#messageBox{
    border-right: 1px solid #000000;
    position: absolute;
    width: 217px;
    height: 100px;
    z-index: 1;
    background-color: #C0C0C0;
    border-style: solid;
    border-width: 1px;
    display:none;
}
#closeButt{
     width: 100%;
     height: 10px;
     z-index: 1;
     cursor: pointer;
     left: 0px;
     top: 0px;
     background-color: #808080;
}
#contents{
    width: 100%;
    height: auto;
    z-index: 2;
}
</style>
<script language="javascript">
function show(obj,msg){
messageBox.style.top=obj.offsetTop
messageBox.style.left=obj.offsetLeft+obj.offsetWidth+5
contents.innerHTML=msg+"<p>"+obj.href
messageBox.style.display="block"
}
</script></head><body>
<p><a onmouseover="show(this,'this is my message#1')" href="http://www.google.com">link1: go to google</a></p>
<p><a onmouseover="show(this,'this is my message#2')" href="http://www.msn.com">link2: go to msn</a></p>
<p><a onmouseover="show(this,'this is my message#3')" href="http://www.dreamincode.com/">link3: go to DIC</a></p>
<div id="messageBox">
    <div onclick="messageBox.style.display='none'" id="closeButt">x Click to close</div>
    <div id="contents"></div>
</div></body></html>
Source: ahmad_511; http://www.dreamincode.net/forums/showtopic44814.htm