davidjerleke / embla-carousel

A lightweight carousel library with fluid motion and great swipe precision.
https://www.embla-carousel.com
MIT License
6.3k stars 187 forks source link

[Bug]: Slide resize cancels animation #1039

Closed viters closed 1 month ago

viters commented 1 month ago

Which variants of Embla Carousel are you using?

Steps to reproduce

See example: https://codesandbox.io/p/sandbox/embla-carousel-slides-to-scroll-react-forked-qrgrfs?file=%2Fsrc%2Fjs%2FEmblaCarousel.tsx%3A49%2C61

If you have dynamic content {active === index ? `test${index}` : 'test'} then animation onScroll does not work properly. Change it to static test and it works perfectly fine.

https://github.com/user-attachments/assets/041b943a-bef8-4669-91bd-36bde20f31af

Expected Behavior

Honestly I am not sure if this is by design - that animation does reset when slides resize. Maybe it is just impossible to calculate? Just wanted to let you know and see your thoughts.

What browsers are you seeing the problem on?

Firefox and Chrome.

Version

8.3.0

CodeSandbox

https://codesandbox.io/p/sandbox/embla-carousel-slides-to-scroll-react-forked-qrgrfs?file=%2Fsrc%2Fjs%2FEmblaCarousel.tsx%3A49%2C61

Before submitting

davidjerleke commented 1 month ago

@viters thanks for your question. This is expected behavior but you can solve it like this for most use cases: