Skip to content

[Help]: How to get the html node of the current slide? #1031

Closed Answered by davidjerleke
dehghani-mehdi asked this question in Help
Discussion options

You must be logged in to vote

@dehghani-mehdi like this:

function getSelectedSlideNode(emblaApi) {
  const selectedIndex = emblaApi.selectedScrollSnap()
  return emblaApi.slideNodes()[selectedIndex]
}

// Usage on init:
const selectedSlideNode = getSelectedSlideNode(emblaApi)

// Usage when the selected slide changes:
emblaApi.on('select', (emblaApi) => {
  const selectedSlideNode = getSelectedSlideNode(emblaApi)
})

Important

This only works if you don't group slides with slidesToScroll. If you do, let me know and I'll show how you get all slide nodes that belong to a specific index/group.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dehghani-mehdi
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