Embla-carousel: Scroll one slide at a time

Created on 21 Nov 2020  路  3Comments  路  Source: davidcetinkaya/embla-carousel

Hi David! Thank you for your work on embla-carousel, it's been a joy to use so far in my project :)

Is it possible to move one slide at a time when slidesToScroll is set to 2 or more? This is what I'm asking for, visualized:

Expected:
Screen Shot 2020-11-20 at 5 09 53 PM

What's happening:
Screen Shot 2020-11-20 at 5 12 11 PM

Sandbox: https://codesandbox.io/s/embla-carousel-default-react-forked-scfoz?file=/src/js/EmblaCarousel.js

demonstration resolved

Most helpful comment

Hi Patrick (@patrickhuang94),

Thank you for your question. Based on your description, I think you're looking for the align option rather than slidesToScroll. Because the purpose of slidesToScroll is to merge slides into the given number and make them act as if it was a single slide. Let's take slidesToScroll: 2 as an example:

slidesToScroll

As you can see, Embla treats every 2 slides as if it was a single slide behind the scenes. In order to achieve what you want, you'll have to do the following:

  • Create a carousel and set slide widths to 50% each.
  • Add the option align: 'start' because we want the slides to align to the left edge of the viewport.
  • Add the option containScroll: 'trimSnaps' to trim any leading/trailing scroll space.
  • Leave the slidesToScroll option to its default value which is 1.

Take a look at this CodeSandbox I created for you and let me know if it helps.

Best,
David

All 3 comments

Hi Patrick (@patrickhuang94),

Thank you for your question. Based on your description, I think you're looking for the align option rather than slidesToScroll. Because the purpose of slidesToScroll is to merge slides into the given number and make them act as if it was a single slide. Let's take slidesToScroll: 2 as an example:

slidesToScroll

As you can see, Embla treats every 2 slides as if it was a single slide behind the scenes. In order to achieve what you want, you'll have to do the following:

  • Create a carousel and set slide widths to 50% each.
  • Add the option align: 'start' because we want the slides to align to the left edge of the viewport.
  • Add the option containScroll: 'trimSnaps' to trim any leading/trailing scroll space.
  • Leave the slidesToScroll option to its default value which is 1.

Take a look at this CodeSandbox I created for you and let me know if it helps.

Best,
David

@davidcetinkaya this is exactly what I was looking for. Thank you for the breakdown!

You鈥檙e welcome @patrickhuang94. Enjoy!

Was this page helpful?
0 / 5 - 0 ratings