flickity icon indicating copy to clipboard operation
flickity copied to clipboard

Carousel snaps into place after calling resize while freescrolling

Open gedrick opened this issue 4 years ago • 0 comments

This is a tough one to recreate in CodePen as it relies on a specific condition. In our case, we are lazy loading images in a freeScroll horizontal (fairly standard) carousel, each of which may be a different height, and thus we are calling resize every time an image loads in the carousel to adjust for potential new heights.

In short, in the flickity.resize method, selectCell is being called with an indiscriminate true for isInstant as the third parameter, which causes the carousel to instantly snap into place potentially while the user is freescrolling. I was able to fix this by replacing this line in flickity.prototype.resize:

this.selectCell( selectedElement, false, true );

with this line

this.selectCell( selectedElement, false, !this.options.freeScroll );

This works nicely with freeScroll turned on or off.

gedrick avatar Nov 06 '19 16:11 gedrick