Skip to content

Commit

Permalink
refactor(esl-carousel): fix the final position of the slide
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-murashko committed Feb 7, 2024
1 parent dee4dfb commit 4105755
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/modules/esl-carousel/renderers/multi/esl-multi-carousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

0 comments on commit 4105755

Please sign in to comment.