-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infinite looping of children #9
Comments
@oyeanuj Thanks.
This is a relatively easy thing to do, however I think with this approach we will get a "backwards" animation and it won't feel like an infinite loop. I think we should add copies or move slides to the next / prev positions to make it look infinite. Anyway PR's are more than welcome, so feel free to hop in. 👋 |
How to enable infinite loop property? |
@Anu-Ujin #17 was not added, you can read my comment about it. I am working on this feature these days (finally got some time to do it). I hope i can make it happen by the end of this month or next. |
Not sure if it worth it (since @sag1v is already working on this feature) but for now I got it working with a bit of logic: const itemsPerPage = 3
const items = [...]
const carouselRef = useRef(null);
const totalPages = Math.ceil(items.length / itemsPerPage)
let resetTimeout;
<Carousel
ref={carouselRef}
enableAutoPlay
autoPlaySpeed={1500} // same time
onNextEnd={({ index }) => {
clearTimeout(resetTimeout)
if (index + 1 === totalPages) {
resetTimeout = setTimeout(() => {
carouselRef.current.goTo(0)
}, 1500) // same time
}
}}
itemsToShow={itemsPerPage}
>
{items.map(() => ...)}
</Carousel> This still doesn't feel like an infinite loop, is more like a "backwards" animation |
@christo-pr Not sure why you had to use the timer, but you are right in that it feels like going backwards. I mentioned this in my comment above #9 (comment) |
The timer is just to mimic the Thanks for the work! |
Hello, how's the infinite scroll feature coming up? A lot of us would appreciate it if you added the feature to the official package. thanks and more power :) |
bump ^ :) |
Root change and give me error, TypeError: Cannot read property 'goTo' of null |
Yeah, well this year was brutal for me (time wise) and i didn't have much time to work on that feature as i thought i would. Gonna try free some time this month |
how to enable loop in react elastic carousel |
Can't wait the infinite :) |
What if i have custom breakpoints for responsive for example
What will i do in this situation |
I do like @sag1v and it work 👍 const carouselRef = React.useRef(null);
const onNextStart = (currentItem, nextItem) => {
if (currentItem.index === nextItem.index) {
// we hit the last item, go to first item
carouselRef.current.goTo(0);
}
};
const onPrevStart = (currentItem, nextItem) => {
if (currentItem.index === nextItem.index) {
// we hit the first item, go to last item
carouselRef.current.goTo(universities.length);
}
}; <Carousel
className='carousel-university'
breakPoints={breakPoints}
ref={carouselRef}
onPrevStart={onPrevStart}
onNextStart={onNextStart}
disableArrowsOnEnd={false}
> It's work good when I click the button prev or next but when I use MOUSE SWIPE next at the last item it's go to the second item not first item (itemsToShow is 1) |
Any update on this? Thank you! |
Any update on this? |
Hi @sag1v thanks for the great carousel slider! It's 2022 now and we're still waiting for infinite loop! Thanks! |
try this it's working for me
|
Hi, @sag1v thanks for the great carousel slider! we're waiting for an infinite loop. Thanks! |
Hi @sag1v still waiting on the infinite loop. Thanks! |
Solution:
|
Thanks a lot @criscar1998 , worked for me! |
I did this to create a infinite loop effect (NOTE: I works only with arrow button, with auto play it stops at last slide) // replace infinite array with your array name // const carouselRef = React.useRef(null); const onNextStart = (currentItem, nextItem) => { <Carousel LET ME KNOW IF YOU CAN MAKE IT WORK WITH AUTOPLAY WITH THIS REFERENCE... |
Best Solution:
|
This solution is worked for me:
|
Hey Sagiv did u create a loop function already? |
Sagiv did u create infinite function? because when we import elastic dynnamically in next js that gotTo(0) function not working |
Perfect Solution ✅: <Carousel breakPoints={breakpoint} loop={true}
|
Hi @sag1v, thank you for creating this library!
Describe the solution you'd like
I'd love to be able to loop through to the first item, if I click on "next" from the last item, so creating an infinite loop of the children.
Describe alternatives you've considered
Maybe using an event handler to see if this is the last child, in which case
onNext
can callgoTo
with the first slide index?The text was updated successfully, but these errors were encountered: