jeudi 18 janvier 2018

Randomize a div position.

I'm very new to programming so be patient please. I've made a program where you press a button and a div positions itself randomly.

function Init()
   {
   div = document.getElementById("pixel");
   spaceW = screen.height - div.height;
   spaceH = screen.width - div.width;
   setInterval(moveIt, 1000);
   }
   function moveIt()
   {
   div.style.top = (100*Math.random()) + "%";
   div.style.left = (100*Math.random()) + "%";
   }

The thing is, it only works when i use the setInterval. I only want the div to move ONCE. I'll erase the setInterval, and then what? Thank you!




Aucun commentaire:

Enregistrer un commentaire