每次刷新
默认生成一百个随机⚪,大小
,颜色
,位置
随机。
<style> div { position: fixed; border-radius: 50%; } </style>
<script> for (var i = 0; i < 100; i++) { //创建元素 var div = document.createElement("div") div.classList.add("div") // var widts = Math.random() * 50 + 30 var tops = Math.random() * (innerHeight - widts) var lefts = Math.random() * (innerWidth - widts) console.log(tops); console.log(lefts); div.style.width = widts + "px" div.style.height = widts + "px" div.style.left = lefts + "px" div.style.top = tops + "px" //0-255 function cl() { return col1 = Math.floor(Math.random() * 256) } var r = cl() var g = cl() var b = cl() div.style.backgroundColor = `rgb(${r},${g},${b})` document.body.append(div) } </script>
<body> </body>