-
-
Notifications
You must be signed in to change notification settings - Fork 239
Description
Which variants of Embla Carousel are you using?
- embla-carousel (Core)
- embla-carousel-react
- embla-carousel-vue
- embla-carousel-svelte
- embla-carousel-autoplay
- embla-carousel-auto-scroll
- embla-carousel-solid
- embla-carousel-auto-height
- embla-carousel-class-names
- embla-carousel-fade
- embla-carousel-docs (Documentation)
- embla-carousel-docs (Generator)
Steps to reproduce
import useEmblaCarousel from 'embla-carousel-react'
import Autoplay from 'embla-carousel-autoplay'
import { useCartelera } from '../../store/useCartelera'
import { useEffect, useRef } from 'react'
import { isVideoHTML } from '../../utils/isVideo'
const SlideWrapper = ({ children }: { children: React.ReactNode }) => {
const { getPreferencias } = useCartelera()
const preferencias = getPreferencias()
const autoplay = useRef(Autoplay({ delay: preferencias?.delay, stopOnInteraction: false }))
const [emblaRef, emblaApi] = useEmblaCarousel({ loop: true, align: 'start' }, [autoplay.current])
useEffect(() => {
if (!emblaApi || !emblaApi.plugins().autoplay) return
const handlerAutoPlay = () => {
const currentSlide = emblaApi.slideNodes()[emblaApi.selectedScrollSnap()]
const isVideo = isVideoHTML(currentSlide)
if (isVideo) {
console.log('Pause autoplay')
autoplay.current.stop()
}
if (!isVideo) {
console.log('Reset autoplay')
autoplay.current.reset()
}
}
emblaApi.on('select', handlerAutoPlay)
}, [emblaApi])
return (
{children}
)
}
export default SlideWrapper
Expected Behavior
Calling autoplay.stop() should immediately pause the autoplay loop and prevent further automatic scrolling until resumed manually.
Additional Context
I’m facing an issue with the Embla Autoplay plugin where autoplay.stop() doesn’t actually pause autoplay. The condition that detects when the current slide contains a video works correctly — the log confirms it — but autoplay keeps running as if stop() had never been called.
The only way I’ve managed to stop autoplay is by calling autoplay.destroy(), which is not suitable because I need to re-enable autoplay afterward without fully rebuilding the plugin.
What browsers are you seeing the problem on?
Safari
Version
No response
CodeSandbox
No response
Before submitting
- I've made research efforts and searched the documentation
- I've searched for existing issues
- I agree to follow this project's Contributing Guidelines for bug reports