|
-
Mar 22nd, 2003, 10:07 AM
#1
Thread Starter
Fanatic Member
changing position randomly
hi there,
this is the layer..
<style>
#mem{color:white;background-color:"black";position:absolute;top:20;left:30;}
</style>
..and this is the "random number"..
rn=Math.floor(Math.random()*400)+1
--now I want to change the position of my "mem-layer" randomly
each time I refresh my page..I want to change the position of both"top(y) and left(x)"according
to the number selected randomly(rn)
can you help me? I wrote.."top:rn;left:rn;" but it did not work
thanks a lot indeed.
-
Mar 23rd, 2003, 03:20 AM
#2
Here's HTML, CSS and JavaScript for that:
Code:
...
<style type="text/css">
#mem {
color:#FFF;
background-color:#000;
position:absolute;
top:20px;
left:30px;
}
</style>
<script type="text/javascript" language="JavaScript">
function onLoad() {
// this must be browser-specific, this way works in Mozillla and IE6+
var mem = document.getElementById("mem");
mem.style.left = (Math.floor(Math.random()*400)+1) + "px";
mem.style.top = (Math.floor(Math.random()*400)+1) + "px";
}
</script>
</head>
<body onload="onLoad()">
<div id="mem" name="mem">
...
</div>
...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 23rd, 2003, 09:59 AM
#3
Thread Starter
Fanatic Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|