Skip to content

Commit 04b05b0

Browse files
morningDclaude
andcommitted
Pause PixelRobots animation when banner lightbox is open
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 26934a9 commit 04b05b0

10 files changed

Lines changed: 27 additions & 2 deletions

File tree

docs/.vitepress/components/PixelRobots.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ let lastTime = 0
6767
let resizeObs = null
6868
let visibilityObs = null
6969
let isVisible = false
70+
let lightboxOpen = false
7071
let sceneReady = false
7172
let nextSpawn = 0
7273
let skyFrame = 0
@@ -487,9 +488,13 @@ function startLoop() {
487488
function stopLoop() {
488489
if (animFrame) { cancelAnimationFrame(animFrame); animFrame = 0 }
489490
}
491+
function onLightboxChange(e) {
492+
lightboxOpen = e.detail.open
493+
if (!lightboxOpen && isVisible) startLoop()
494+
}
490495
function tick(time) {
491496
animFrame = 0
492-
if (!isVisible) return
497+
if (!isVisible || lightboxOpen) return
493498
const dt = lastTime ? Math.min((time - lastTime) / 16, 3) : 1
494499
lastTime = time
495500
const w = container.value?.offsetWidth || 800
@@ -921,7 +926,7 @@ function tick(time) {
921926
if (spores.value.length) triggerRef(spores)
922927
if (wxParticles.value.length && weather.value.type !== 'clear') triggerRef(wxParticles)
923928
924-
if (isVisible) animFrame = requestAnimationFrame(tick)
929+
if (isVisible && !lightboxOpen) animFrame = requestAnimationFrame(tick)
925930
}
926931
927932
// ── Drag ──
@@ -992,6 +997,7 @@ onMounted(() => {
992997
// stopLoop happens naturally: tick() checks isVisible before scheduling next frame
993998
}, { rootMargin: '100px' }) // start slightly before entering viewport
994999
if (container.value) visibilityObs.observe(container.value)
1000+
window.addEventListener('lightbox-change', onLightboxChange)
9951001
})
9961002
onUnmounted(() => {
9971003
if (resizeObs) resizeObs.disconnect()
@@ -1001,6 +1007,7 @@ onUnmounted(() => {
10011007
window.removeEventListener('pointermove', onMove)
10021008
window.removeEventListener('pointerup', onUp)
10031009
window.removeEventListener('resize', onResizeThrottled)
1010+
window.removeEventListener('lightbox-change', onLightboxChange)
10041011
})
10051012
10061013
// ── Helpers ──

docs/ar/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ function openLightbox(e) {
101101
if (e.target.closest('a')) return
102102
lightboxOpen.value = true
103103
resetTransform()
104+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: true } }))
104105
}
105106

106107
function closeLightbox() {
107108
lightboxOpen.value = false
108109
pointers.clear()
109110
pinching = false
110111
if (rafId) { cancelAnimationFrame(rafId); rafId = 0 }
112+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: false } }))
111113
}
112114

113115
function resetTransform() {

docs/es/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ function openLightbox(e) {
102102
if (e.target.closest('a')) return
103103
lightboxOpen.value = true
104104
resetTransform()
105+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: true } }))
105106
}
106107

107108
function closeLightbox() {
108109
lightboxOpen.value = false
109110
pointers.clear()
110111
pinching = false
111112
if (rafId) { cancelAnimationFrame(rafId); rafId = 0 }
113+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: false } }))
112114
}
113115

114116
function resetTransform() {

docs/fr/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ function openLightbox(e) {
102102
if (e.target.closest('a')) return
103103
lightboxOpen.value = true
104104
resetTransform()
105+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: true } }))
105106
}
106107

107108
function closeLightbox() {
108109
lightboxOpen.value = false
109110
pointers.clear()
110111
pinching = false
111112
if (rafId) { cancelAnimationFrame(rafId); rafId = 0 }
113+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: false } }))
112114
}
113115

114116
function resetTransform() {

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ function openLightbox(e) {
102102
if (e.target.closest('a')) return
103103
lightboxOpen.value = true
104104
resetTransform()
105+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: true } }))
105106
}
106107

107108
function closeLightbox() {
108109
lightboxOpen.value = false
109110
pointers.clear()
110111
pinching = false
111112
if (rafId) { cancelAnimationFrame(rafId); rafId = 0 }
113+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: false } }))
112114
}
113115

114116
function resetTransform() {

docs/ja/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ function openLightbox(e) {
102102
if (e.target.closest('a')) return
103103
lightboxOpen.value = true
104104
resetTransform()
105+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: true } }))
105106
}
106107

107108
function closeLightbox() {
108109
lightboxOpen.value = false
109110
pointers.clear()
110111
pinching = false
111112
if (rafId) { cancelAnimationFrame(rafId); rafId = 0 }
113+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: false } }))
112114
}
113115

114116
function resetTransform() {

docs/ko/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ function openLightbox(e) {
102102
if (e.target.closest('a')) return
103103
lightboxOpen.value = true
104104
resetTransform()
105+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: true } }))
105106
}
106107

107108
function closeLightbox() {
108109
lightboxOpen.value = false
109110
pointers.clear()
110111
pinching = false
111112
if (rafId) { cancelAnimationFrame(rafId); rafId = 0 }
113+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: false } }))
112114
}
113115

114116
function resetTransform() {

docs/ru/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ function openLightbox(e) {
102102
if (e.target.closest('a')) return
103103
lightboxOpen.value = true
104104
resetTransform()
105+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: true } }))
105106
}
106107

107108
function closeLightbox() {
108109
lightboxOpen.value = false
109110
pointers.clear()
110111
pinching = false
111112
if (rafId) { cancelAnimationFrame(rafId); rafId = 0 }
113+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: false } }))
112114
}
113115

114116
function resetTransform() {

docs/zh-tw/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ function openLightbox(e) {
102102
if (e.target.closest('a')) return
103103
lightboxOpen.value = true
104104
resetTransform()
105+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: true } }))
105106
}
106107

107108
function closeLightbox() {
108109
lightboxOpen.value = false
109110
pointers.clear()
110111
pinching = false
111112
if (rafId) { cancelAnimationFrame(rafId); rafId = 0 }
113+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: false } }))
112114
}
113115

114116
function resetTransform() {

docs/zh/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ function openLightbox(e) {
102102
if (e.target.closest('a')) return
103103
lightboxOpen.value = true
104104
resetTransform()
105+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: true } }))
105106
}
106107

107108
function closeLightbox() {
108109
lightboxOpen.value = false
109110
pointers.clear()
110111
pinching = false
111112
if (rafId) { cancelAnimationFrame(rafId); rafId = 0 }
113+
window.dispatchEvent(new CustomEvent('lightbox-change', { detail: { open: false } }))
112114
}
113115

114116
function resetTransform() {

0 commit comments

Comments
 (0)