Carousel re-init on very small width change #569
Replies: 2 comments 6 replies
-
Hi @hamidrezahanafi, Thanks for your input. Yes it will react to any change because that's how ResizeObserver works. Sometimes this may be the wanted behaviour and sometimes not. I can't rule out that this is the wanted behaviour in some cases. It's impossible for me to know. However, if you read the docs, Embla gives you the freedom to provide your own callback and customise the resize behaviour. For convenience, it gives you the const [emblaRef, emblaApi] = useEmblaCarousel({
watchResize: (emblaApi, resizeObserverEntries) => {
// you can also access the current rects like this:
const { slideRects, containerRect } = emblaApi.internalEngine()
// do your own thing and run reInit() when you think the carousel should reset and pick up changes
if (yourCustomConditionIsMet) emblaApi.reInit()
// return false so Embla doesn't fire it's default resize behaviour after your custom callback
return false
}
}) Best, |
Beta Was this translation helpful? Give feedback.
6 replies
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone,
I checked that resize observer can react to very small width/height changes for example in my case the change was from 163.890625 => 163.89060974121094 (which I think it's not actual change and is rounding of the browser)
Is it a good idea if the condition of new size vs old size to be more than 1 pixel instead of not equal?
Beta Was this translation helpful? Give feedback.
All reactions