[Feat]: Dont cross loop when using scrollTo #1121
-
Which variants of Embla Carousel are relevant to this feature request?
Feature description#1091 is great, but it still needs the developer to calculate if the scrolling should be doen backward/forward manually. It would be great to have an option that prevents scrollTo to cross the loop. In other words: Same scroll behavior as if there would be no loop. Personally I would prefer an option over a prop. Additional ContextAdditional details here... Before submitting
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi @MickL, Thank you for your feature request. I understand that having this built-in would be convenient, but I need to carefully evaluate each request to determine if it should be added, considering factors like bundle size and other implications. This is the first time this feature has been requested, so I would need more traction before considering it for inclusion in the core library. While it’s possible others have thought about it, no one has yet submitted a request. I hope that makes sense. In the meantime, you can use this snippet: function scrollToDontCrossLoop(targetIndex: number): void {
if (!emblaApi) return;
const { index } = emblaApi.internalEngine();
const direction = index.get() > targetIndex ? 1 : -1;
emblaApi.scrollTo(targetIndex, false, direction);
} I'm closing this for now and if it gets more traction in the future, I will consider adding it to the library core. Thanks for understanding! |
Beta Was this translation helpful? Give feedback.
Hi @MickL,
Thank you for your feature request.
I understand that having this built-in would be convenient, but I need to carefully evaluate each request to determine if it should be added, considering factors like bundle size and other implications. This is the first time this feature has been requested, so I would need more traction before considering it for inclusion in the core library. While it’s possible others have thought about it, no one has yet submitted a request. I hope that makes sense.
In the meantime, you can use this snippet: