metafizzy / flickity

:leaves: Touch, responsive, flickable carousels
https://flickity.metafizzy.co
7.52k stars 605 forks source link

Cells shifting on append. Intentional? #921

Closed W1zzardTPU closed 5 years ago

W1zzardTPU commented 5 years ago

When the carousel is scrolled all the way to the end and items are appended, the whole carousel shifts. Is this intentional? Any way to disable this behavior?

https://codepen.io/anon/pen/xBeWVy

jimmyadaro commented 5 years ago

My guess is that the scroll position of the slider viewport remains the same. You could use selectCell after append the elements and select the current length - 1 (because is zero-based).

...
var cellElems = [ makeCell(), makeCell() ];
  flkty.append( cellElems);
  flkty.selectCell( flkty.cells.length - 1 ); //Add this
...

https://codepen.io/anon/pen/GLWOPG?editors=0010

desandro commented 5 years ago

Thanks for reporting this issue.

The issue is that is that contain makes it hard for Flickity to decide which cell is selected when you're at the end. So when you append new cells, it selects the closest one. Thus it shifts a bit. So one way to resolve this is to disable contain.

I feel this is an edge case. I appreciate you reporting the problem, but I'd like to focus my attention elsewhere.