diff --git a/components/checkout/FeatureSlideshow.tsx b/components/checkout/FeatureSlideshow.tsx index a9147d0..d172b82 100644 --- a/components/checkout/FeatureSlideshow.tsx +++ b/components/checkout/FeatureSlideshow.tsx @@ -38,8 +38,22 @@ export default function FeatureSlideshow() { }, []) useEffect(() => { - const timer = setInterval(advance, 8000) - return () => clearInterval(timer) + let timer: ReturnType | null = null + + const start = () => { timer = setInterval(advance, 8000) } + const stop = () => { if (timer) { clearInterval(timer); timer = null } } + + const onVisibility = () => { + if (document.hidden) stop() + else start() + } + + start() + document.addEventListener('visibilitychange', onVisibility) + return () => { + stop() + document.removeEventListener('visibilitychange', onVisibility) + } }, [advance]) const slide = slides[activeIndex]