[Help]: How to get the html node of the current slide? #1031
-
Summary
If applicable, which variants of Embla Carousel are relevant to this question?
Additional informationNo response CodeSandbox exampleNo response |
Beta Was this translation helpful? Give feedback.
Answered by
davidjerleke
Oct 15, 2024
Replies: 1 comment
-
@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 |
Beta Was this translation helpful? Give feedback.
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
@dehghani-mehdi like this:
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.