Skip to content

Commit

Permalink
fix infinite scrolling when clicking prev button
Browse files Browse the repository at this point in the history
  • Loading branch information
mxkae committed May 15, 2024
1 parent 088e5ff commit 8c1affa
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/block/carousel/frontend-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,15 @@ class _StackableCarousel {
}

if ( setScrollToClone ) {
// Move from the last slide to the first slide (N - next) or
// Move from the first slide to the last slide (P - prev)
this.sliderEl.style.scrollBehavior = 'unset'
this.sliderEl.scrollLeft = dir === 'N'
? this.clones[ this.currentSlide - 1 ].offsetLeft
: this.slideEls[ this.currentSlide - 1 ].offsetLeft
? this.clones[ this.currentSlide - 1 ].offsetLeft // Go to the last clone slide
: ( this.slidesToShow === 1
? this.clones[ this.currentSlide - 1 ].offsetLeft // If slidesToShow is 1, go to the first clone slide
: this.slideEls[ this.currentSlide - 1 ].offsetLeft // Go to the original first slide which is swapped with the clone
)
this.sliderEl.style.scrollBehavior = ''
}

Expand Down

0 comments on commit 8c1affa

Please sign in to comment.