这可能会让你继续:
http://codepen.io/anon/pen/FjrxA
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Random Boxes</title>
</head>
<body>
<script>
// Make a loop to create a random amount of boxes
var box_count = Math.random() * 100 + 50;
for (var i = 0; i < box_count; i++) {
// Define an array of css attributes
var attr =[
// Assign a colour to the box
'background-color:#' + parseInt(Math.random() * 0xFFFFFF, 10).toString(16),
// Place the box somewhere inside the window
'left:' + Math.random() * window.innerWidth + 'px',
'top:' + Math.random() * window.innerHeight + 'px',
// Give the box a random size
'width:' + Math.random() * 100 + 'px',
'height:' + Math.random() * 100 + 'px','position: absolute'
];
// Join the attributes together with semi-colon and write the div to the document
// Note: Document write happens at the place where the script is executed
document.write('<div style="' + attr.join(';') +'"></div>');
}
</script>
</body>
</html>