Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DHTML, Can anybody please help, layers and positioning 2

Status
Not open for further replies.

maybe

Instructor
Jul 11, 2001
14
0
0
GB
Using the onMouseOver event, is it possible to find the exact position of the a layer, pass that position on to another layer, and then show the second layer, replacing the first.
 
yeah it is. I had to do this recently and used the offesetLeft and offsetTop properties. Ill give u an example:

Code:
<script type=&quot;text/javascript&quot;>
function replaceIt(oldDivID,newDivID){
  document.getElementById(newDivID).style.left=document.getElementById(oldDivID).offsetLeft;
  document.getElementById(newDivID).style.top=document.getElementById(oldDivID).offsetTop;
  document.getElementById(oldDivID).style.visibility=&quot;hidden&quot;;
  document.getElementById(newDivId).style.visibility=&quot;visible&quot;;
}
</script>
<body>
<div id=&quot;oldDiv&quot; onmouseover=&quot;replaceIt('oldDiv','newDiv')&quot;>content</div>
<div id=&quot;newDiv&quot; style=&quot;visibility:hidden&quot;>content</div>
</body>

of course its not that simple. You will need the usual workarounds for netscape 4 and other non DOM browsers (e.g. IE4). and as well the offset property behaves differently between IE and netscape. Basically different parent elements behave differently between the two. for example if you have nested layers/Divs the offsetLeft retrurns the number of pixels difference between the left value of the parent and child elements so you would need to add the offset of the parent from the body to gain the overall offset of the child element. Also one of them treats tables as block level (and hence a parent element) and one doesnt (so would look for the parent element above that.

have a play with it - ypu should be able to get something working.

good luck

hope it helps
rob

 
sorry maybe!!

i just been having another look at that property(offsetTop and offsetLeft) and it seems it is IE4+ only and any DOM browsers but not Netscrap 4.x. It is supported in NS6 tho (DOM)....

if u are not bothered about ns4 then its cool to use it otherwise you'll have to find another workaround

sorry hope it this still helps u

rob
 
hi there
for netscrap - use
document.layers.name.left
document.layers.name.top Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top