Skip to content
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

Added infinite-ish scroll feature #17

Closed
wants to merge 2 commits into from
Closed

Added infinite-ish scroll feature #17

wants to merge 2 commits into from

Conversation

AustinLeeGordon
Copy link

Implemented an infinite scroll option as mentioned in #9

@sag1v I know you mentioned adding copies to make it actually appear to be infinite, but I think this is a good start for now for anyone who wants to use it as is. I personally don't mind the backwards scroll.

Seems like creating copies would be very inefficient, but I don't see a way to easily get around that.

Since it's not truly infinite, it will stop on the first/last item when it has potential to scroll past it. Here's an example:

infinite scroll example

I had issues trying to put together a demo page, so I left that mess out, but I did test it out on the current demos.

Let me know what you think!

@sag1v
Copy link
Owner

sag1v commented Jun 8, 2019

Thanks for the effort @AustinLeeGordon nicely done !
I think the feature in this way is not fully "baked" though, on top of that you can easily achieve this behavior in "user-land":

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(items.length);
  }
};

// .....

<Carousel
  ref={carouselRef}
  onPrevStart={onPrevStart}
  onNextStart={onNextStart}
>
  {items}
</Carousel>

I still think we should copy the items and only render the visible ones (itemsToShow) + itemsToScroll.
Given 50 items, with itemsToShow: 2, itemsToScroll: 1 we will render:

hidden visible visible hidden
[50] [1] [2] [3]

This is also necessary for lazy loading which i also want to support (though it is achievable in user land as well)

What are your thoughts?

@AustinLeeGordon
Copy link
Author

@sag1v Agreed. I looked at some other carousels with infinite scroll and this seems to be the best way to do it.

@sag1v sag1v closed this Sep 19, 2019
@Anu-Ujin
Copy link

Anu-Ujin commented Sep 21, 2020

@AustinLeeGordon Is there any infinite loop carousel demo? There is no infinite section in doc. I write infinite={true} in the Carousel but not working.
My version is "react-elastic-carousel": "^0.7.4"

@sag1v
Copy link
Owner

sag1v commented Sep 21, 2020

@Anu-Ujin There is no infinite section in demos because its not supported yet.

@venkateshr407
Copy link

How can I add an infinite loop section for react-elastic-carousel, please help me

@Neelam-Nishad
Copy link

Neelam-Nishad commented Nov 26, 2021

Thanks for the effort @AustinLeeGordon nicely done ! I think the feature in this way is not fully "baked" though, on top of that you can easily achieve this behavior in "user-land":

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(items.length);
  }
};

// .....

<Carousel
  ref={carouselRef}
  onPrevStart={onPrevStart}
  onNextStart={onNextStart}
>
  {items}
</Carousel>

I still think we should copy the items and only render the visible ones (itemsToShow) + itemsToScroll. Given 50 items, with itemsToShow: 2, itemsToScroll: 1 we will render:

hidden visible visible hidden
[50] [1] [2] [3]
This is also necessary for lazy loading which i also want to support (though it is achievable in user land as well)

What are your thoughts?

How to loop using this? the buttons are getting disabled everytime on reaching the last element.

edit: solution is (disableArrowsOnEnd={false})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants