Skip to content

[Help]: Change main slide when thumbs autoscroll #727

Closed Answered by davidjerleke
coldnanee asked this question in Help
Discussion options

You must be logged in to vote

Hi @coldnanee,

Thanks for your question. That's possible to achieve. A simple implementation would be:

thumbsCarouselApi.on('select', () => {
  mainCarouselApi.scrollTo(thumbsCarouselApi.selectedScrollSnap())
})

However, you might not want to disturb a user if they're dragging the main carousel by switching slide. So we can check if the pointer is down on the main carousel and only advance it when the pointer isn't down like so:

const mainCarouselPointerDown = useRef(false)

useEffect(() => {
  function setPointerState(api, eventName) {
    mainCarouselPointerDown.current = eventName === 'pointerDown'
  }
  mainCarouselApi
    .on('pointerDown', setPointerState)
    .on('pointerUp', setPo…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by coldnanee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
resolved This issue is resolved question Question about how to achieve something
2 participants