Created
November 30, 2017 17:47
-
-
Save shinecita/2d048f458c605e77d2a9b29d1fb9d817 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
ngOnChanges(changes: SimpleChanges) { | |
if (this.currentSlide !== undefined && !changes.currentSlide.firstChange) { | |
this.move(); | |
this.renderer.setElementClass(this.carouselItems[(this.currentSlide + this.center) % this.carouselItems.length ], 'faded', true); | |
this.renderer.setElementClass(this.carouselItems[(this.currentSlide + this.center + 1) % this.carouselItems.length], 'faded', true); | |
this.setFade(); | |
this.setFade(); | |
} | |
} | |
ngAfterViewInit() { | |
this.itemWidth = this.carouselItems[0].clientWidth + 4; | |
this.center = Math.floor(this.carouselItems.length / 2); | |
this.setLayout(); | |
this.move(); | |
} | |
private setStyle(el: any, prop: any, val: any): void { | |
this.renderer.setElementStyle(el, prop, val); | |
} | |
setFade( index: number ) { | |
const lastSlide = (this.currentSlide + this.center) % this.carouselItems.length | |
const firstSlide = (this.currentSlide + this.center + 1) % this.carouselItems.length | |
this.renderer.setElementClass(this.carouselItems[lastSlide], 'faded', true); | |
this.renderer.setElementClass(this.carouselItems[firstSlide], 'faded', true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment