Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll one slide at a time #121

Closed
patrickhuang94 opened this issue Nov 21, 2020 · 3 comments
Closed

Scroll one slide at a time #121

patrickhuang94 opened this issue Nov 21, 2020 · 3 comments
Labels
question Question about how to achieve something resolved This issue is resolved

Comments

@patrickhuang94
Copy link

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

@davidjerleke
Copy link
Owner

davidjerleke commented Nov 21, 2020

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

@davidjerleke davidjerleke added awaiting response Issue is awaiting feedback question Question about how to achieve something labels Nov 21, 2020
@patrickhuang94
Copy link
Author

patrickhuang94 commented Nov 23, 2020

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

@davidjerleke davidjerleke added resolved This issue is resolved and removed awaiting response Issue is awaiting feedback labels Nov 23, 2020
@davidjerleke
Copy link
Owner

You’re welcome @patrickhuang94. Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about how to achieve something resolved This issue is resolved
Projects
None yet
Development

No branches or pull requests

2 participants