Skip to content

Instantly share code, notes, and snippets.

@shinecita
Created November 30, 2017 17:47
Show Gist options
  • Save shinecita/2d048f458c605e77d2a9b29d1fb9d817 to your computer and use it in GitHub Desktop.
Save shinecita/2d048f458c605e77d2a9b29d1fb9d817 to your computer and use it in GitHub Desktop.
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