- 1afterTransition(callback) {
- 2 const handler = () => {
- 3 callback();
- 4 this.$refs.carouselInner.removeEventListener('transitionend', handler);
- 5 this.isTransitioning = false;
- 6 };
- 7 this.$refs.carouselInner.addEventListener('transitionend', handler);
- 8},
- 9
- 10withoutTransition(fn) {
- 11 this.disableTransition();
- 12 fn();
- 13 this.$refs.carouselInner.offsetHeight; // Force reflow
- 14 setTimeout(() => this.enableTransition(), 50);
- 15},
- 16
- 17next() {
- 18 if (this.isTransitioning) return;
- 19 this.isTransitioning = true;
- 20 this.currentSlide++;
- 21 const maxIndex = this.originalSlides.length * 2;
- 22 this.afterTransition(() => {
- 23 if (this.currentSlide >= maxIndex) {
- 24 this.withoutTransition(() => {
- 25 this.currentSlide -= this.originalSlides.length;
- 26 });
- 27 }
- 28 });
- 29},
- 30
- 31prev() {
- 32 if (this.isTransitioning) return;
- 33 this.isTransitioning = true;
- 34 this.currentSlide--;
- 35 this.afterTransition(() => {
- 36 if (this.currentSlide < this.originalSlides.length) {
- 37 this.withoutTransition(() => {
- 38 this.currentSlide += this.originalSlides.length;
- 39 });
- 40 }
- 41 });
- 42},
Raw Paste