From 41057556c240e8e6107ae0c6095896614ab3ca81 Mon Sep 17 00:00:00 2001 From: ymurashka Date: Wed, 7 Feb 2024 19:55:45 +0300 Subject: [PATCH] refactor(esl-carousel): fix the final position of the slide --- .../renderers/multi/esl-multi-carousel.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/modules/esl-carousel/renderers/multi/esl-multi-carousel.ts b/src/modules/esl-carousel/renderers/multi/esl-multi-carousel.ts index 70f27b7b6..037de606a 100644 --- a/src/modules/esl-carousel/renderers/multi/esl-multi-carousel.ts +++ b/src/modules/esl-carousel/renderers/multi/esl-multi-carousel.ts @@ -167,13 +167,9 @@ export class ESLMultiCarouselRenderer extends ESLCarouselRenderer { 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; @@ -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,