Results 1 to 3 of 3

Thread: changing position randomly

  1. #1

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    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.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  3. #3

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601
    thanks a lot indeed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width