js parabola, random colors

 
div:nth-of-type(1){
width: 600px;
height: 2px;
background: #000;
position: absolute;
top: 300px;
}
div:nth-of-type(2){
width: 2px;
height: 600px;
background: #000;
position: absolute;
left: 300px;
}
span{
display: block;
position: absolute;
width:2px;
height:2px;
background: #000;
}
 

 
<div></div>
<div></div>
<script>
for(var x = -300; x <= 300; x++){
var y = -0.003 * Math.pow (x, 2);
document.write('<span style="top:'+ (y + 300) +'px;left:'+ (x + 300) +'px;"></span>');
 
}
 
</script>
 
//random color
// function randomColor(){
// where
// r = parseInt(Math.random() * 256).toString(16).length < 2 ? "0" + parseInt(Math.random() * 256).toString(16) : parseInt(Math.random() * 256).toString(16);
// g = parseInt(Math.random() * 256).toString(16).length < 2 ? "0" + parseInt(Math.random() * 256).toString(16) : parseInt(Math.random() * 256).toString(16);
// b = parseInt(Math.random() * 256).toString(16).length < 2 ? "0" + parseInt(Math.random() * 256).toString(16) : parseInt(Math.random() * 256).toString(16);
// return "#" + r + g + b;
// }
// document.body.style.background = randomColor();

Guess you like

Origin www.cnblogs.com/wenlx/p/11458335.html