Skip to content
This repository has been archived by the owner on Mar 6, 2022. It is now read-only.

Scroll up on next item #13

Closed
ankitprahladsoni opened this issue Jul 6, 2021 · 2 comments
Closed

Scroll up on next item #13

ankitprahladsoni opened this issue Jul 6, 2021 · 2 comments

Comments

@ankitprahladsoni
Copy link

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.

@Emiliano-Bucci
Copy link
Owner

Emiliano-Bucci commented Jul 6, 2021

@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!

@ankitprahladsoni
Copy link
Author

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

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

No branches or pull requests

2 participants