|
24 | 24 | position: absolute; |
25 | 25 | border-radius: 50%; |
26 | 26 | opacity: 0.4; |
27 | | - animation: float 120s linear infinite; |
| 27 | + animation: float var(--particle-duration, 120s) linear infinite; |
28 | 28 | transform-origin: 50vw 50vh; |
29 | 29 | } |
30 | 30 | @keyframes float { |
|
39 | 39 | <script> |
40 | 40 | (function() { |
41 | 41 | const container = document.getElementById('particles'); |
| 42 | + const baseSize = 1920 * 1080; |
| 43 | + |
| 44 | + // 画面サイズに応じてアニメーション速度を計算 |
| 45 | + function calcDuration() { |
| 46 | + const currentSize = window.innerWidth * window.innerHeight; |
| 47 | + const ratio = Math.sqrt(currentSize / baseSize); |
| 48 | + return Math.max(20, Math.min(80, 80 * ratio)); |
| 49 | + } |
| 50 | + |
| 51 | + function updateParticleDuration() { |
| 52 | + const duration = calcDuration(); |
| 53 | + document.documentElement.style.setProperty('--particle-duration', duration + 's'); |
| 54 | + } |
| 55 | + updateParticleDuration(); |
| 56 | + window.addEventListener('resize', updateParticleDuration); |
| 57 | + |
42 | 58 | const colors = { |
43 | 59 | h: ['#7c6cae', '#8b7cb8', '#6a5a9e', '#9b8bc8', '#5d4d8e'], |
44 | 60 | e: ['#e8a0b0', '#f0b0c0', '#dca0b0', '#f5c0d0', '#d890a0'] |
45 | 61 | }; |
46 | 62 | const count = 20; |
| 63 | + const initialDuration = calcDuration(); |
47 | 64 | for (let i = 0; i < count; i++) { |
48 | 65 | const el = document.createElement('div'); |
49 | 66 | el.className = 'particle'; |
|
56 | 73 | el.style.left = Math.random() * 100 + '%'; |
57 | 74 | el.style.top = Math.random() * 100 + '%'; |
58 | 75 | el.style.background = `radial-gradient(circle, ${color} 0%, transparent 70%)`; |
59 | | - el.style.animationDelay = -Math.random() * 120 + 's'; |
| 76 | + el.style.animationDelay = -Math.random() * initialDuration + 's'; |
60 | 77 | el.style.animationDirection = Math.random() > 0.5 ? 'normal' : 'reverse'; |
61 | 78 | container.appendChild(el); |
62 | 79 | } |
|
0 commit comments