(function() { const section = document.querySelector('#circle-section'); const circles = document.querySelectorAll('.cursor-circle'); if (!section || circles.length === 0) return; // Настройки для ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ ΠΊΡ€ΡƒΠ³Π° const configs = [ { speed: 0.08, offsetX: -40, offsetY: -40 }, // circle-1 { speed: 0.16, offsetX: 0, offsetY: 0 }, // circle-2 { speed: 0.26, offsetX: 20, offsetY: 20 } // circle-3 ]; let mouseX = 0; let mouseY = 0; let positions = configs.map(() => ({ x: 0, y: 0 })); let active = false; // ΠŸΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΈ сСкции ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ ΠΎΠΊΠ½Π° function getSectionRect() { return section.getBoundingClientRect(); } // Π”Π²ΠΈΠΆΠ΅Π½ΠΈΠ΅ ΠΌΡ‹ΡˆΠΈ ΠΏΠΎ Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Ρƒ document.addEventListener('mousemove', (e) => { const rect = getSectionRect(); // ΠŸΡ€ΠΎΠ²Π΅Ρ€ΡΠ΅ΠΌ, находится Π»ΠΈ курсор Π²Π½ΡƒΡ‚Ρ€ΠΈ сСкции if ( e.clientY >= rect.top && e.clientY <= rect.bottom && e.clientX >= rect.left && e.clientX <= rect.right ) { active = true; mouseX = e.clientX - rect.left; mouseY = e.clientY - rect.top; circles.forEach(c => c.style.opacity = 1); } else { active = false; circles.forEach(c => c.style.opacity = 0); } }); // Анимационный Ρ†ΠΈΠΊΠ» function animate() { if (active) { circles.forEach((circle, index) => { const cfg = configs[index]; const pos = positions[index]; pos.x += (mouseX - pos.x) * cfg.speed; pos.y += (mouseY - pos.y) * cfg.speed; circle.style.transform = `translate(${pos.x + cfg.offsetX}px, ${pos.y + cfg.offsetY}px)`; }); } requestAnimationFrame(animate); } // Π‘Ρ‚Π°Ρ€Ρ‚ const rect = getSectionRect(); positions = configs.map(() => ({ x: rect.width / 2, y: rect.height / 2 })); animate(); })();