[Help]: Autoplay starts from zero on hover out when stopOnMouseEnter
and stopOnInteraction
are used.
#1027
-
SummaryI'm using Embla Carousel with a combination of This is how I am tracking the progress and play/pause my custom progress bar: const [emblaRef, emblaApi] = useEmblaCarousel(
{
loop: true,
axis: 'y',
},
[
Autoplay({
delay: 4000,
stopOnMouseEnter: true,
stopOnFocusIn: true,
stopOnInteraction: false,
}),
Fade(),
]
)
const { selectedIndex, scrollSnaps, onThumbnailClick } =useThumbnail(emblaApi)
const [progressKey, setProgressKey] = useState(0)
const [isPlaying, setIsPlaying] = useState(true)
useEffect(() => {
if (emblaApi) emblaApi.rootNode().classList.remove('opacity-0')
}, [emblaApi])
useEffect(() => {
setProgressKey((prev) => prev + 1)
}, [selectedIndex])
useEffect(() => {
if (!emblaApi) return
// Event handler for autoplay pause
const handleAutoplayPause = () => {
setIsPlaying(false)
}
// Event handler for autoplay play
const handleAutoplayPlay = () => {
setIsPlaying(true)
}
// Attach event listeners
emblaApi.on('autoplay:stop', handleAutoplayPause)
emblaApi.on('autoplay:play', handleAutoplayPlay)
// Clean up event listeners on unmount
return () => {
emblaApi.off('autoplay:stop', handleAutoplayPause)
emblaApi.off('autoplay:play', handleAutoplayPlay)
}
}, [emblaApi]) Please let me know if you believe that I am doing something wrong. Thank you! If applicable, which variants of Embla Carousel are relevant to this question?
Additional informationNo response CodeSandbox exampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
@todor0v have you seen the new progress bar I've added to the autoplay example in the docs? With recent changes, it's now easy to build a progress bar that doesn't get out of sync. See this: |
Beta Was this translation helpful? Give feedback.
-
There's a feature request for this now and it has been added to the roadmap: |
Beta Was this translation helpful? Give feedback.
There's a feature request for this now and it has been added to the roadmap: