|
| 1 | +--- |
| 2 | +// Animated starfield background component |
| 3 | +// Creates a twinkling star effect with two layers of stars |
| 4 | +// that move, scale, rotate, and change opacity |
| 5 | +--- |
| 6 | + |
| 7 | +<div class="animated-stars"> |
| 8 | + <slot /> |
| 9 | +</div> |
| 10 | + |
| 11 | +<style> |
| 12 | + .animated-stars { |
| 13 | + position: relative; |
| 14 | + width: 100%; |
| 15 | + min-height: 100vh; |
| 16 | + } |
| 17 | + |
| 18 | + .animated-stars::before { |
| 19 | + content: ''; |
| 20 | + position: absolute; |
| 21 | + top: 0; |
| 22 | + left: 0; |
| 23 | + width: 100%; |
| 24 | + height: 100%; |
| 25 | + background-image: |
| 26 | + radial-gradient(1px 1px at 10% 20%, white, transparent), |
| 27 | + radial-gradient(1px 1px at 30% 40%, white, transparent), |
| 28 | + radial-gradient(1px 1px at 50% 60%, white, transparent), |
| 29 | + radial-gradient(1px 1px at 70% 30%, white, transparent), |
| 30 | + radial-gradient(1px 1px at 90% 80%, white, transparent), |
| 31 | + radial-gradient(1px 1px at 15% 70%, white, transparent), |
| 32 | + radial-gradient(1px 1px at 40% 15%, white, transparent), |
| 33 | + radial-gradient(1px 1px at 60% 85%, white, transparent), |
| 34 | + radial-gradient(1px 1px at 85% 50%, white, transparent), |
| 35 | + radial-gradient(1px 1px at 25% 90%, white, transparent); |
| 36 | + background-size: |
| 37 | + 200px 200px, |
| 38 | + 250px 250px, |
| 39 | + 300px 300px, |
| 40 | + 180px 180px, |
| 41 | + 220px 220px, |
| 42 | + 280px 280px, |
| 43 | + 240px 240px, |
| 44 | + 260px 260px, |
| 45 | + 290px 290px, |
| 46 | + 210px 210px; |
| 47 | + background-position: |
| 48 | + 0 0, |
| 49 | + 40px 60px, |
| 50 | + 130px 270px, |
| 51 | + 70px 100px, |
| 52 | + 220px 180px, |
| 53 | + 300px 320px, |
| 54 | + 150px 80px, |
| 55 | + 280px 380px, |
| 56 | + 100px 200px, |
| 57 | + 350px 250px; |
| 58 | + background-repeat: repeat; |
| 59 | + animation: twinkle1 45s ease-in-out infinite; |
| 60 | + pointer-events: none; |
| 61 | + z-index: 0; |
| 62 | + } |
| 63 | + |
| 64 | + .animated-stars::after { |
| 65 | + content: ''; |
| 66 | + position: absolute; |
| 67 | + top: 0; |
| 68 | + left: 0; |
| 69 | + width: 100%; |
| 70 | + height: 100%; |
| 71 | + background-image: |
| 72 | + radial-gradient(2px 2px at 20% 15%, rgba(255,255,255,0.8), transparent), |
| 73 | + radial-gradient(1px 1px at 45% 35%, white, transparent), |
| 74 | + radial-gradient(1px 1px at 65% 55%, rgba(255,255,255,0.7), transparent), |
| 75 | + radial-gradient(2px 2px at 80% 25%, white, transparent), |
| 76 | + radial-gradient(1px 1px at 35% 75%, rgba(255,255,255,0.9), transparent), |
| 77 | + radial-gradient(1px 1px at 55% 45%, white, transparent); |
| 78 | + background-size: |
| 79 | + 300px 300px, |
| 80 | + 200px 200px, |
| 81 | + 250px 250px, |
| 82 | + 280px 280px, |
| 83 | + 220px 220px, |
| 84 | + 240px 240px; |
| 85 | + background-position: |
| 86 | + 0 0, |
| 87 | + 50px 80px, |
| 88 | + 100px 150px, |
| 89 | + 200px 50px, |
| 90 | + 150px 200px, |
| 91 | + 250px 100px; |
| 92 | + background-repeat: repeat; |
| 93 | + animation: twinkle2 60s ease-in-out infinite; |
| 94 | + pointer-events: none; |
| 95 | + z-index: 0; |
| 96 | + } |
| 97 | + |
| 98 | + .animated-stars > :global(*) { |
| 99 | + position: relative; |
| 100 | + z-index: 1; |
| 101 | + } |
| 102 | + |
| 103 | + @keyframes twinkle1 { |
| 104 | + 0% { |
| 105 | + opacity: 1; |
| 106 | + transform: translate(0, 0) scale(1); |
| 107 | + } |
| 108 | + 15% { |
| 109 | + opacity: 0.4; |
| 110 | + transform: translate(25px, -15px) scale(1.1); |
| 111 | + } |
| 112 | + 30% { |
| 113 | + opacity: 0.8; |
| 114 | + transform: translate(-20px, 30px) scale(0.9); |
| 115 | + } |
| 116 | + 45% { |
| 117 | + opacity: 0.3; |
| 118 | + transform: translate(30px, 20px) scale(1.05); |
| 119 | + } |
| 120 | + 60% { |
| 121 | + opacity: 0.9; |
| 122 | + transform: translate(-25px, -25px) scale(0.95); |
| 123 | + } |
| 124 | + 75% { |
| 125 | + opacity: 0.5; |
| 126 | + transform: translate(15px, 35px) scale(1.08); |
| 127 | + } |
| 128 | + 90% { |
| 129 | + opacity: 0.7; |
| 130 | + transform: translate(-30px, -10px) scale(0.92); |
| 131 | + } |
| 132 | + 100% { |
| 133 | + opacity: 1; |
| 134 | + transform: translate(0, 0) scale(1); |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + @keyframes twinkle2 { |
| 139 | + 0% { |
| 140 | + opacity: 0.8; |
| 141 | + transform: translate(0, 0) rotate(0deg); |
| 142 | + } |
| 143 | + 20% { |
| 144 | + opacity: 0.3; |
| 145 | + transform: translate(-30px, 20px) rotate(5deg); |
| 146 | + } |
| 147 | + 35% { |
| 148 | + opacity: 0.9; |
| 149 | + transform: translate(25px, -25px) rotate(-3deg); |
| 150 | + } |
| 151 | + 50% { |
| 152 | + opacity: 0.4; |
| 153 | + transform: translate(-15px, -30px) rotate(7deg); |
| 154 | + } |
| 155 | + 65% { |
| 156 | + opacity: 0.7; |
| 157 | + transform: translate(35px, 15px) rotate(-5deg); |
| 158 | + } |
| 159 | + 80% { |
| 160 | + opacity: 0.5; |
| 161 | + transform: translate(-20px, 28px) rotate(4deg); |
| 162 | + } |
| 163 | + 100% { |
| 164 | + opacity: 0.8; |
| 165 | + transform: translate(0, 0) rotate(0deg); |
| 166 | + } |
| 167 | + } |
| 168 | + |
| 169 | + @media (prefers-reduced-motion: reduce) { |
| 170 | + .animated-stars::before, |
| 171 | + .animated-stars::after { |
| 172 | + animation: none; |
| 173 | + } |
| 174 | + } |
| 175 | +</style> |
0 commit comments