question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`loop` doesn't work when displaying three slides out of four total slides

See original GitHub issue

Hi,

When the total number of slides is set to 4, slidesToShow: 3, and slidesToScroll: 1, the loop option stops working. This was mentioned in the docs, which is probably what’s happening

loop
... Automatically falls back to false if slide content isn't enough to loop.

This can be reproduced in the sandbox: https://codesandbox.io/s/embla-carousel-loop-react-forked-7200i?file=/src/js/index.js

Two questions:

  1. What’s the reasoning for this restriction? There’s definitely enough slide content to loop. I was expecting to see [1,2,3] on initial render, [2,3,4] on next click, and [3,4,1] on next click.
  2. Is there a workaround for this?

Thanks, Patrick

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
davidjerlekecommented, Mar 3, 2021

Hello Patrick (@patrickhuang94),

Thank you for your question and the CodeSandbox. The documentation is correct, Embla Carousel will check if there is enough slide content to make the loop effect work without any flickering (white space showing).

  1. What’s the reasoning for this restriction? There’s definitely enough slide content to loop. I was expecting to see [1,2,3] on initial render, [2,3,4] on next click, and [3,4,1] on next click.

Now, assuming you have 4 slides, you would think that setting the CSS like this:

.embla__slide {
  min-width: 33.33333%;
}

/* ...or a nicer way to put it */

.embla__slide {
  min-width: calc(100% / 3);
}

…would result in enough content to make the loop effect work. But this isn’t the case. Because the viewport is 100%. And the slide content for 3 slides (we subtract 1 slide because it’s needed to flip around for the loop effect to work) will be 33.33333 * 3 = 99.99999%. Additionally, when I log the slide sizes calculated from the boundingClientRect, the browser gives 33.331691216316074, which isn’t even 33.33333%.

I hope this explanation makes sense.

  1. Is there a workaround for this?

There’s no workaround for this other than writing your own fallback logic. For example, you can duplicate the slides yourself.

Best, David

0reactions
davidjerlekecommented, Mar 7, 2021

@patrickhuang94 I’m closing this as resolved. You’re welcome to open this issue again if you don’t agree.

Best, David

Read more comments on GitHub >

github_iconTop Results From Across the Web

loop doesn't work when displaying three slides out of four total ...
Hi, When the total number of slides is set to 4, slidesToShow: 3, and slidesToScroll: 1, the loop option stops working.
Read more >
How to Loop a PowerPoint in 5 Simple Steps - G2 Learning Hub
1. Click Slide Show · 2. Click Set Up Slide Show · 3. Click Loop continuously · 4. Select all slides and click...
Read more >
How to add a looping introduction to a PowerPoint presentation
Enter the number of seconds you want to pause between slides—3 (Figure B). Click the Slide Show tab, and then click Set Up...
Read more >
Swiper js showing 3 identical slides when there is one slide
Simply change the loop parameter from true to false.
Read more >
How to Make PowerPoint Loop | PowerPoint Repeat Slideshow
When you setup a PowerPoint loop slideshow, it runs by itself from the first to the last slide, rewinds itself, and runs again....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found