feat(andreknie.de): improve accessibility and initial loading
This commit is contained in:
@@ -15,6 +15,8 @@ export default function BackgroundPattern() {
|
||||
const canvas = canvasRef.current
|
||||
if (!canvas) return
|
||||
const ctx = canvas.getContext('2d')
|
||||
const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
||||
const accentColor = getComputedStyle(document.documentElement).getPropertyValue('--accent-color').trim() || '#4a9eff'
|
||||
|
||||
function resize() {
|
||||
const dpr = window.devicePixelRatio || 1
|
||||
@@ -61,8 +63,6 @@ export default function BackgroundPattern() {
|
||||
const h = window.innerHeight
|
||||
ctx.clearRect(0, 0, w, h)
|
||||
|
||||
const style = getComputedStyle(document.documentElement)
|
||||
const accentColor = style.getPropertyValue('--accent-color').trim() || '#4a9eff'
|
||||
const mouse = mouseRef.current
|
||||
const repelRadius = 80
|
||||
|
||||
@@ -99,14 +99,21 @@ export default function BackgroundPattern() {
|
||||
ctx.globalAlpha = 1
|
||||
})
|
||||
|
||||
animRef.current = requestAnimationFrame(animate)
|
||||
if (!reducedMotion && !document.hidden) animRef.current = requestAnimationFrame(animate)
|
||||
}
|
||||
|
||||
function handleVisibilityChange() {
|
||||
if (document.hidden) cancelAnimationFrame(animRef.current)
|
||||
else if (!reducedMotion) animate()
|
||||
}
|
||||
|
||||
animate()
|
||||
document.addEventListener('visibilitychange', handleVisibilityChange)
|
||||
return () => {
|
||||
cancelAnimationFrame(animRef.current)
|
||||
window.removeEventListener('resize', resize)
|
||||
window.removeEventListener('mousemove', handleMouseMove)
|
||||
document.removeEventListener('visibilitychange', handleVisibilityChange)
|
||||
}
|
||||
}, [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user