Skip to content

[Help]: How to add classes to previous and next slides in loop mode? #986

Closed Answered by Filip1139
Filip1139 asked this question in Help
Discussion options

You must be logged in to vote

I achieve what I need by using this code:

  embla.on('select', () => handleSlideExtraClassnames(embla))

  function handleSlideExtraClassnames(emblaApi) {
    const engine = emblaApi.internalEngine();
    const activeSnapIndex = emblaApi.selectedScrollSnap();
    const lastIndex = engine.slideRegistry.length - 1;

    const previousSnapSlides =
      activeSnapIndex === 0 ? engine.slideRegistry[lastIndex] : engine.slideRegistry[activeSnapIndex - 1];

    const nextSnapSlides =
      activeSnapIndex === lastIndex ? engine.slideRegistry[0] : engine.slideRegistry[activeSnapIndex + 1];

    emblaApi.slideNodes().forEach((slide, index) => {
      slide.classList.remove('is-slide-prev', 'is-sli…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

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

@Filip1139
Comment options

Answer selected by davidjerleke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
question Question about how to achieve something
2 participants