space.html (784B)
1 {% macro stars(num) -%} 2 <style> 3 .star { 4 position: absolute; 5 background-color: white !important; 6 width: 1px; 7 height: 1px; 8 } 9 </style> 10 <script> 11 function randomPosition() { 12 var rw = Math.floor(Math.random() * window.innerWidth); 13 var rh = Math.floor(Math.random() * window.innerHeight); 14 return [rw, rh]; 15 } 16 17 function createStars() { 18 document.querySelectorAll(".star").forEach(element => element.remove()); 19 for (let i = 0; i < {{ num }}; i++) { 20 let star = document.createElement("div"); 21 star.className = "star"; 22 var [w, h] = randomPosition(); 23 star.style.top = h + "px"; 24 star.style.left = w + "px"; 25 document.body.append(star); 26 } 27 } 28 createStars(); 29 window.onresize = createStars; 30 </script> 31 {%- endmacro %}