Emiliano-Bucci/react-spring-carousel-js

Scroll up on next item

ankitprahladsoni opened this issue · 2 comments

I'm working on a carousel where every item has a lot of text and the user has to scroll down to read it. When the user swipes left or right to go to some other item, it doesn't scroll to the top.
Is there any way in which the next or previous slide always scrolls to the top?
PS: The items will be of variable lengths and I'm only targeting mobile devices.

@ankitprahladsoni Hi!

I guess that you could listen for the onSlideStartChange event and manually scroll the scrollable container to the top.

useListenToCustomEvent(event => {
    if (event.eventName === 'onSlideStartChange') {
      const scrollableContainer = document.querySelector('.scrollable-container')
      scrollableContainer.scrollTo(0, 0)
    }
  })

Something like that :)

Please let me know if that helps!

Yes, it does. However, I had to do window.scrollTo(0,0) inside useListenToCustomEvent. Thanks for the response