nir9 / itemslide

JavaScript Touch Carousel Library with Zero Dependencies
https://itemslide.org
MIT License
647 stars 85 forks source link

Clamp to half width if outer container contains an even number of elements #54

Closed PurHur closed 8 years ago

PurHur commented 8 years ago

The items will clamp to the half width if the outer container contains (in the visible part) an even number of elements. If its uneven it works perfect.

Did anybody encounter this problem before?

PurHur commented 8 years ago

The bug is in getPositionByIndex

    return -(i * slides.children().outerWidth(true) - ((slides.parent().outerWidth(true) - slides.children().outerWidth(true)) / 2))

i think the / 2 is only useful if the slider is not a left_sided.

nir9 commented 8 years ago

I don't really get the problem i'm now testing and i see no problem when there is an even amount of elements. can you provide an example that doesn't work (jsfiddle or something)?

PurHur commented 8 years ago

Here you go: http://jsfiddle.net/k0vh8jwc/1/ (pull the testing window to full size)

with -[margin right of an item](not / 2) it works

nir9 commented 8 years ago

Ok i see, i'll work on a fix.

nir9 commented 8 years ago

Added your fix, thanks.