davidjerleke / embla-carousel

A lightweight carousel library with fluid motion and great swipe precision.
https://www.embla-carousel.com
MIT License
5.39k stars 166 forks source link

Scroll snap and slides to scroll calculations are too sensitive #649

Closed mozart77 closed 6 months ago

mozart77 commented 6 months ago

Bug is related to

Embla Carousel version

Describe the bug

Function scrollSnapList() returns wrong number of elements.

CodeSandbox

- The link to a CodeSandbox that demonstrates the bug clearly.

Steps to reproduce

  1. Take example with dots from Generator
  2. Remove one slide
  3. Add breakpoints in CSS to change number of slides displayed
  4. Watch the number of pages when all slides are visible. There will be 2 pages

Expected behavior

One page or none when all slides are visible

Additional context

Video: https://github.com/davidjerleke/embla-carousel/assets/6299334/8bfdba46-2969-4411-9751-50c8b9477eaf

mozart77 commented 6 months ago

Another example if we remove max-width from container (watch the dots!)

https://github.com/davidjerleke/embla-carousel/assets/6299334/fba9ffec-2852-45cc-b6b6-340fb3d1deb9

davidjerleke commented 6 months ago

Hi @mozart77,

Thank you for your bug report. Yes I’ve actually noted this issues. They are most likely caused by the transition from reading element.getBoundingClientRect to offset dimensions (e. g. offsetWidth, offsetLeft):

I basically missed to refactor the rounding safeties used in the code. Because client rects give you floating points which is why it was needed before while offset dimensions return whole integers so this is probably causing problems now. I will look into this when possible. Thanks for creating a bug so devs can track this issue.

Best, David

davidjerleke commented 6 months ago

Hi @mozart77,

Would you mind testing the following CodeSandbox and see if it behaves as expected now? Please let me know if you intend to test it or not so you don't leave me hanging. Thanks!

Best, David

davidjerleke commented 6 months ago

@mozart77 a bug fix for this was just released in v8.0.0-rc16.