You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Embla Carousel with a combination of stopOnMouseEnter and stopOnInteraction. This causes an undesired behavior. Specifically, when you hover out, instead of the animation continuing from where it left off, it resets to zero. For example, you have to wait another four seconds for the next slide to appear, rather than skipping the time that already passed before you hovered. I'm using a progress bar that tracks the time until the next slide, which makes this issue very noticeable.
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 pauseconsthandleAutoplayPause=()=>{setIsPlaying(false)}// Event handler for autoplay playconsthandleAutoplayPlay=()=>{setIsPlaying(true)}// Attach event listenersemblaApi.on('autoplay:stop',handleAutoplayPause)emblaApi.on('autoplay:play',handleAutoplayPlay)// Clean up event listeners on unmountreturn()=>{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?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Summary
I'm using Embla Carousel with a combination of
stopOnMouseEnter
andstopOnInteraction
. This causes an undesired behavior. Specifically, when you hover out, instead of the animation continuing from where it left off, it resets to zero. For example, you have to wait another four seconds for the next slide to appear, rather than skipping the time that already passed before you hovered. I'm using a progress bar that tracks the time until the next slide, which makes this issue very noticeable.This is how I am tracking the progress and play/pause my custom progress bar:
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 information
No response
CodeSandbox example
No response
Beta Was this translation helpful? Give feedback.
All reactions