[Help]: loop: true
not working when images have variable width
#413
-
Hey David, thanks for your work on Embla. I think it's a lovely library, and I've used it successfully before. However in my latest React project I have a problem that I can't be able to solve. I am using I have built a custom React component around Embla, that accepts Images with Captions via a prop. When I use this component in Isolation (in my component gallery/storybook), everything works great (including the However if I use the component "in production" inside of my project (which uses Astro as a site generator), I always get this error when I load a page containing the Image slider, and the images never "wrap" around (the space to the left of the first image is always empty) I am trying to debug this problem further, but I'm a little lost on how to find the culprit/problem. Something in my setup seems to conflict with Embla, as I cannot recreate this in isolation. Any ideas on how to approach this problem? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 18 replies
-
Hi @pReya, Thank you for your question. My guess would be that there are no slides when you initialize the Embla script. Try only attaching the
Let me know if that’s the culprit or not. Best, |
Beta Was this translation helpful? Give feedback.
-
@davidjerleke Sorry for digging this up again. I am really confused: Is it possible to use Embla (in general) and also the loop option with dynamic width slides (e.g. not just variable as in "every slide has a different, but known/static width that we can put into css" but rather dynamic as in "we don't know how big these images are beforehand, b/c they come from user-editable content or an external API")? If not, then what is the docs section for, where you mention using the If yes, I really think this should be mentioned in the docs or there should be an example for "dynamic width slides". |
Beta Was this translation helpful? Give feedback.
Hi @pReya,
Thank you for your question. My guess would be that there are no slides when you initialize the Embla script. Try only attaching the
emblaRef
when you have any slides and passnull
when there aren’t any like so:ref={slides.length > 0 ? emblaRef : null}
Let me know if that’s the culprit or not.
Best,
David