react-elastic-carousel: Infinite looping of children
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 call goTo with the first slide index?
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 4
- Comments: 29 (4 by maintainers)
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 😃
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:
This still doesn’t feel like an infinite loop, is more like a “backwards” animation
@oyeanuj Thanks. This could be a great addition to
react-elastic-carouselindeed!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. Of course we would need to consider all edge cases like 1 visible item vs 12 visible items for example.
Anyway PR’s are more than welcome, so feel free to hop in. 👋
Solution:
Any update on this?
I do like @sag1v and it work 👍
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)
Can’t wait the infinite 😃
This solution is worked for me:
@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.
Hi @sag1v thanks for the great carousel slider! It’s 2022 now and we’re still waiting for infinite loop!
Thanks!
The timer is just to mimic the
autoPlaySpeedthat’s why I mention it in my example, looking forward to use theinifiteprop.Thanks for the work!
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 // //infinite array is a state I create which store my array ( since my array comes from API)
const carouselRef = React.useRef(null);
const onNextStart = (currentItem, nextItem) => { if (currentItem.index === nextItem.index) { // carouselRef.current.goTo(0); const newArray = […infiniteArray]; newArray.push(newArray.shift()); setInfiniteArray(newArray); } }; const onPrevStart = (currentItem, nextItem) => { if (currentItem.index === nextItem.index) { const newArray = […infiniteArray]; newArray.unshift(newArray.pop()); setInfiniteArray(newArray); } };
<Carousel breakPoints={breakPoints} // enableAutoPlay // autoPlaySpeed={5000} infiniteLoop={true} renderArrow={myArrow} className=‘carouselMain’ dots={true} ref={carouselRef} onPrevStart={onPrevStart} onNextStart={onNextStart} >
LET ME KNOW IF YOU CAN MAKE IT WORK WITH AUTOPLAY WITH THIS REFERENCE… UPVOTE IF IT HELPS YOU…
Hi, @sag1v thanks for the great carousel slider! we’re waiting for an infinite loop.
Thanks!