Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e875564

Browse files
authoredFeb 12, 2024
Merge pull request #2224 from exadel-inc/feat/esl-carousel-rework
feat(esl-carousel-rework): fix jumping during commit animation & fix the final position of the slide
2 parents 0bb5eda + 4105755 commit e875564

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
 

‎src/modules/esl-carousel/renderers/multi/esl-multi-carousel.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,16 @@ export class ESLMultiCarouselRenderer extends ESLCarouselRenderer {
160160
const slideSize = this.slideSize + this.gap;
161161
// calculate offset to move to
162162
const shiftCount = Math.abs(offset) % slideSize >= slideSize / 4 ? 1 : 0;
163-
const stageOffset = offset < 0 ? -shiftCount * slideSize : (shiftCount - 1) * slideSize - this.gap;
163+
const stageOffset = offset < 0 ? -shiftCount * slideSize : (shiftCount - 1) * slideSize;
164164

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

170-
// clear animation
171-
this.$carousel.toggleAttribute('animating', false);
172-
this.setTransformOffset(0);
173-
this.$slides.forEach((el) => el.toggleAttribute('visible', false));
174-
175170
const sign = offset < 0 ? 1 : -1;
176-
const count = Math.abs(offset) % this.slideSize >= this.slideSize / 4 ?
171+
const slideSize = this.slideSize + this.gap;
172+
const count = Math.abs(offset) % slideSize >= slideSize / 4 ?
177173
Math.ceil(Math.abs(offset) / this.slideSize) : Math.floor(Math.abs(offset) / this.slideSize);
178174
const nextIndex = this.$carousel.activeIndex + count * sign;
179175

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

190186
this.setActive(this.currentIndex);
191187

188+
// clear animation
189+
this.$carousel.toggleAttribute('animating', false);
190+
this.setTransformOffset(0);
191+
this.$slides.forEach((el) => el.toggleAttribute('visible', false));
192+
192193
if (activeIndex !== this.currentIndex) {
193194
this.$carousel.dispatchEvent(ESLCarouselSlideEvent.create('AFTER', {
194195
direction,

0 commit comments

Comments
 (0)
Please sign in to comment.