探索内在宇宙

15分钟 · 深海游

加载中...

正在连接心灵深处...

深渊
animationId = requestAnimationFrame(animate); return; } ctx.clearRect(0, 0, canvas.width, canvas.height); // 绘制粒子 particles.forEach((p, i) => { // 更新位置 p.x += p.vx * p.speed; p.y += p.vy * p.speed; // 边界处理 if (p.x < 0) p.x = canvas.width; if (p.x > canvas.width) p.x = 0; if (p.y < 0) p.y = canvas.height; if (p.y > canvas.height) p.y = 0; // 绘制粒子 ctx.beginPath(); ctx.arc(p.x, p.y, p.radius, 0, Math.PI * 2); ctx.fillStyle = `rgba(200, 220, 255, ${p.opacity})`; ctx.fill(); // 绘制连线(仅桌面端) if (!isMobile && i % 3 === 0) { particles.slice(i + 1).forEach(p2 => { const dx = p.x - p2.x; const dy = p.y - p2.y; const dist = Math.sqrt(dx * dx + dy * dy); if (dist < 100) { ctx.beginPath(); ctx.moveTo(p.x, p.y); ctx.lineTo(p2.x, p2.y); ctx.strokeStyle = `rgba(78, 205, 196, ${0.1 * (1 - dist / 100)})`; ctx.stroke(); } }); } }); animationId = requestAnimationFrame(animate); } animate(); } // ===== 事件监听 ===== actionRoll.addEventListener('click', rollTest); actionEnter.addEventListener('click', (e) => { e.preventDefault(); const url = actionEnter.href; transitionTo(url); }); searchToggle.addEventListener('click', openSearch); searchClose.addEventListener('click', closeSearch); searchOverlay.addEventListener('click', closeSearch); searchInput.addEventListener('input', (e) => { performSearch(e.target.value); }); searchInput.addEventListener('keydown', (e) => { if (e.key === 'Escape') closeSearch(); }); document.addEventListener('keydown', (e) => { if (e.key === '/' && !isSearching) { e.preventDefault(); openSearch(); } if (e.key === ' ' && !isSearching) { e.preventDefault(); rollTest(); } }); // 目录项点击 catalogList.addEventListener('click', (e) => { if (e.target.classList.contains('catalog-item')) { e.preventDefault(); transitionTo(e.target.href); } }); // 移动端触摸优化 if (isTouchDevice) { actionRoll.addEventListener('touchstart', function() { this.style.transform = 'scale(0.95)'; }); actionRoll.addEventListener('touchend', function() { this.style.transform = ''; }); } // 页面可见性变化时暂停/恢复动画 document.addEventListener('visibilitychange', () => { if (document.hidden && animationId) { cancelAnimationFrame(animationId); } else if (!document.hidden && particles.length > 0) { initCanvas(); } }); // ===== 启动 ===== init();