I am creating a game where you have to follow particles (divs) and click on them to "eat" them. The issue I am having currently is that I can't find a way to clone each div and give it a random X and Y coordinate value to position it.
Here is my code:
var x = e.pageX; var y = e.pageY; function reposition(div, x, y, randomMode) { if(randomMode == 1) { x = Math.floor(Math.random() * 990); y = Math.floor(Math.random() * 560); } $(div).animate({"left": x + "px"}, "slow"); $(div).animate({"top": y + "px"}, "slow"); } // need to find some way to duplicate the divs and move them in random directions setInterval(function() { for(var i = 1; i < 4; i++) { reposition("#grabItem", 0, 0, 1); } }, 2000);