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!

Random location for a layer

Status
Not open for further replies.

GoPo

Technical User
Dec 9, 2003
11
0
0
BE
How can I make a layer popup at a random location on screen ???

Thx

GoPo

---------------------------------------
 
Try this:
Code:
<script language="javascript">
function randomizeDiv(sID)
{	oDiv = document.getElementById( sID );
 	oDiv.style.left = Math.floor(Math.random() *(document.body.clientWidth-oDiv.offsetWidth)) ;
	oDiv.style.top = Math.floor(Math.random() *(document.body.clientHeight-oDiv.offsetHeight)) ;
	oDiv.style.visibility = "visible";
}
</script>

Here is testing code:

Code:
<body onload="randomizeDiv('popupdiv')">
...
<div id="popupdiv" style="position: absolute; height: 100px; width: 200px; border: solid #666699 1px; visibility: hidden;">
Blah blah blah
</div>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top