Skip to content

[Help]: Why is slidesInView giving multiple indices when there should only be 1 index? #948

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

You must be logged in to vote

@dermatobia after testing your CodeSandbox, I think it has to do with fractional pixels. Embla is using the browser native Intersection Observer under the hood and the default threshold is [0], which means that an element will be considered in view even if only half a pixel of it is in view.

To solve this. simply increase the threshold using the Embla inViewThreshold option like so:

const [emblaRef, emblaApi] = useEmblaCarousel({ 
  loop: true, 
  inViewThreshold: 0.001 // <-- Add this
}, [
  Autoplay({
    stopOnInteraction: false,
  }),
]);

Replies: 1 comment 2 replies

Comment options

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

Answer selected by dermatobia
@dermatobia
Comment options

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