Apr 7, 2004 #1 GoPo Technical User Joined Dec 9, 2003 Messages 11 Location BE How can I make a layer popup at a random location on screen ??? Thx GoPo --------------------------------------- http://www.ajouta.be
How can I make a layer popup at a random location on screen ??? Thx GoPo --------------------------------------- http://www.ajouta.be
Apr 7, 2004 #2 vongrunt Programmer Joined Mar 8, 2004 Messages 4,863 Location HR 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> Upvote 0 Downvote
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>