Skip to content

Commit

Permalink
Merge pull request #7 from ralftar/dev-first-slide-on-resize-fix
Browse files Browse the repository at this point in the history
Resize carousel only when width is changed (not height). closes #5
skip ci
  • Loading branch information
ralftar committed Jul 21, 2020
2 parents b7a4c93 + 1076e0b commit 728b9ae
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions projects/carousel/src/lib/carousel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export class MatCarouselComponent
private destroy$ = new Subject<never>();
private playing = false;

private width: number;

constructor(
private animationBuilder: AnimationBuilder,
private renderer: Renderer2,
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 728b9ae

Please sign in to comment.