tiny-slider icon indicating copy to clipboard operation
tiny-slider copied to clipboard

centered doesn't work with decimal item numbers

Open albanyacademy opened this issue 5 years ago • 7 comments

Issue description:
Using a decimal to indicate number of items (e.g. items: 3.3, ) causes the center property to miscalculate the position of the 'centered' slide, failing to account for the offset.

Demo link/slider setting: https://codepen.io/wearingalampshade/pen/rNVmwaw

Tiny-slider version: current Browser name && version: current versions of firefox and chrome OS name && version: max catalina baby

albanyacademy avatar Feb 27 '20 21:02 albanyacademy

This bug was also affecting me but I was able to "fix" it by translating my slides in css.

If I'm supposed to have 1.4 slides, centered, I add the "transform: translateX(20%);" styles to my slide items.

ChatonMeow avatar Jun 08 '20 14:06 ChatonMeow

This bug was also affecting me but I was able to "fix" it by translating my slides in css.

If I'm supposed to have 1.4 slides, centered, I add the "transform: translateX(20%);" styles to my slide items.

Just in case someone stumbles upon this, I can say it works. Thanks for the suggestion!

UrielNicolas avatar Nov 04 '20 15:11 UrielNicolas

Stumbled on this issue as well and ChatonMeow's solution worked.

corina avatar May 24 '21 10:05 corina

this bug still bugs

OwenMagelssen avatar Aug 25 '22 21:08 OwenMagelssen

this bug still bugs

@OwenMagelssen At this point I'd suggest just switching to https://swiperjs.com/, this project hasn't been updated in the last 2 years, while SwiperJS works really great and has integrations with all the common frameworks.

ChatonMeow avatar Aug 25 '22 21:08 ChatonMeow

this bug still bugs

@OwenMagelssen At this point I'd suggest just switching to https://swiperjs.com/, this project hasn't been updated in the last 2 years, while SwiperJS works really great and has integrations with all the common frameworks.

thank you for the recommendation

OwenMagelssen avatar Aug 25 '22 21:08 OwenMagelssen

I think this is due to this line.

Removing the Math.floor rounding function:

items = !autoWidth ? Math.floor(getOption('items')) : 1,

so that it reads:

items = !autoWidth ? getOption('items') : 1,

preserves any decimal value you might assign to it. The horizontal transform for the container is then correctly calculated so that it centers correctly.

jools-r avatar Sep 25 '22 11:09 jools-r