Skip to content

[Help]: How to grab the content in the active/current slide from a different component file? #847

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

You must be logged in to vote

Hi @shyakadavis,

Thank you for your question. For the Embla side of things you need to know what slides are in view, and that's easy:

<script>
  import emblaCarouselSvelte from 'embla-carousel-svelte'

  let emblaApi

  function setSlideInViewToStore(emblaApi) {
    // Returns slide indexes in view in an array format --> Example [3] 
    // NOTE that slide index 3 actually means slide nr. 4 because slide 1 has index 0
    const slidesInView = emblaApi.slidesInView() 
  }

  function onInit(event) {
    emblaApi = event.detail

    emblaApi.on('slidesInView', setSlideInViewToStore) // Update store when slides enter/leave view
    setSlideInViewToStore(emblaApi) // Set store on init
  }
</s…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@shyakadavis
Comment options

@davidjerleke
Comment options

Answer selected by shyakadavis
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 svelte Issue is related to Svelte
2 participants