Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(esl-carousel-rework): fix jumping during commit animation & fix the final position of the slide #2224

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/modules/esl-carousel/renderers/multi/esl-multi-carousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,16 @@ export class ESLMultiCarouselRenderer extends ESLCarouselRenderer {
const slideSize = this.slideSize + this.gap;
// calculate offset to move to
const shiftCount = Math.abs(offset) % slideSize >= slideSize / 4 ? 1 : 0;
const stageOffset = offset < 0 ? -shiftCount * slideSize : (shiftCount - 1) * slideSize - this.gap;
const stageOffset = offset < 0 ? -shiftCount * slideSize : (shiftCount - 1) * slideSize;

this.$carousel.toggleAttribute('animating', true);
this.setTransformOffset(stageOffset);
await promisifyEvent(this.$area, 'transitionend').catch(resolvePromise);
}

// clear animation
this.$carousel.toggleAttribute('animating', false);
this.setTransformOffset(0);
this.$slides.forEach((el) => el.toggleAttribute('visible', false));

const sign = offset < 0 ? 1 : -1;
const count = Math.abs(offset) % this.slideSize >= this.slideSize / 4 ?
const slideSize = this.slideSize + this.gap;
const count = Math.abs(offset) % slideSize >= slideSize / 4 ?
Math.ceil(Math.abs(offset) / this.slideSize) : Math.floor(Math.abs(offset) / this.slideSize);
const nextIndex = this.$carousel.activeIndex + count * sign;

Expand All @@ -189,6 +185,11 @@ export class ESLMultiCarouselRenderer extends ESLCarouselRenderer {

this.setActive(this.currentIndex);

// clear animation
this.$carousel.toggleAttribute('animating', false);
this.setTransformOffset(0);
this.$slides.forEach((el) => el.toggleAttribute('visible', false));

if (activeIndex !== this.currentIndex) {
this.$carousel.dispatchEvent(ESLCarouselSlideEvent.create('AFTER', {
direction,
Expand Down
Loading