davidjerleke / embla-carousel

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

[Bug]: Jitter on resize when not on first image #905

Closed vincvdwal closed 2 weeks ago

vincvdwal commented 2 weeks ago

Which variants of Embla Carousel are you using?

Steps to reproduce

Expected Behavior

On resizing the window, the carousel image should resize smoothly

Additional Context

Apparently, the first image resizes perfectly, only occurs from the second image onwards

What browsers are you seeing the problem on?

Firefox, Chrome, Safari

Version

v8.1.4

CodeSandbox

No response

Before submitting

davidjerleke commented 2 weeks ago

@vincvdwal this is because Embla doesn’t know the carousel container element size beforehand when it changes. It needs to get the new dimensions after a resize and adjust its position based on the new dimensions. That’s why it takes a very brief moment before it positions itself correctly.

You don’t resize the window slowly when using a real world application (at least if you’re not a developer). Most visitors will never even trigger a resize. If they do, it’s probably when they change orientation on a tablet or mobile which will trigger a single resize. And in these cases, it won’t be a problem and it’s negligible.