From 1076e0bc55c49a3b3e637af0ce2cfae0f31d8b7c Mon Sep 17 00:00:00 2001 From: ralftar Date: Tue, 21 Jul 2020 12:17:40 +0200 Subject: [PATCH] Resize carousel only when width is changed (not height). closes #5 --- projects/carousel/src/lib/carousel.component.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/projects/carousel/src/lib/carousel.component.ts b/projects/carousel/src/lib/carousel.component.ts index 9b59a37..2f4424c 100644 --- a/projects/carousel/src/lib/carousel.component.ts +++ b/projects/carousel/src/lib/carousel.component.ts @@ -143,6 +143,8 @@ export class MatCarouselComponent private destroy$ = new Subject(); private playing = false; + private width: number; + constructor( private animationBuilder: AnimationBuilder, private renderer: Renderer2, @@ -162,6 +164,8 @@ export class MatCarouselComponent } public ngAfterViewInit(): void { + this.width = this.getWidth(); + this.autoplay$.pipe(takeUntil(this.destroy$)).subscribe(value => { this.stopTimer(); this.startTimer(value); @@ -243,9 +247,13 @@ export class MatCarouselComponent @HostListener('window:resize', ['$event']) public onResize(event: Event): void { - // Reset carousel when window is resized + // Reset carousel when width is resized // in order to avoid major glitches. - this.slideTo(0); + const w = this.getWidth(); + if (w !== this.width) { + this.width = w; + this.slideTo(0); + } } public onPan(event: any, slideElem: HTMLElement): void {