当前位置:首页 > 前端 > 正文

js 抛物线、随机颜色

  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>   //随机颜色 // function randomColor(){ // var // 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();