-
-
Save arun12209/7139973e6f1285b4e4c938b9db802176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LightningElement, track } from 'lwc'; | |
export default class Carousel extends LightningElement { | |
@track currentSlide = 0; | |
get slides() { | |
return this.template.querySelectorAll('img'); | |
} | |
prev() { | |
if (this.currentSlide > 0) { | |
this.currentSlide--; | |
} | |
} | |
next() { | |
if (this.currentSlide < this.slides.length - 1) { | |
this.currentSlide++; | |
} | |
} | |
connectedCallback() { | |
this.slides[this.currentSlide].classList.add('is-active'); | |
} | |
renderedCallback() { | |
this.slides.forEach(slide => slide.classList.remove('is-active')); | |
this.slides[this.currentSlide].classList.add('is-active'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment