Created
March 6, 2014 22:14
-
-
Save omniosi/9400894 to your computer and use it in GitHub Desktop.
create randomly positioned copies of an object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<style> | |
#box{ | |
width:300px; | |
height:250px; | |
background: lightblue; | |
} | |
#dot{ | |
display:none; | |
} | |
.drop{ | |
width:10px; | |
height:10px; | |
background: grey; | |
position: relative; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="box"> | |
<div id="dot" class="drop"></div> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var box = document.getElementById('box'), | |
dot = document.getElementById('dot'); | |
function getRandomInt(min,max){ | |
return Math.round(Math.random() * (max - min + 1)) + min; | |
} | |
for (var i=0; i<300; i++){ | |
var name = "dot"+i; | |
var drop = dot.cloneNode(true); | |
drop.id = name; | |
box.appendChild(drop); | |
drop.style.top = getRandomInt(0,5) + 'px'; | |
drop.style.left = getRandomInt(0,300) + 'px'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment