Skip to content

Commit

Permalink
fix(module:carousel): fix adaptive when switching screens (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuonuoge authored and Guoyuanqiang committed May 6, 2019
1 parent cfd733e commit 4ff06d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions components/carousel/carousel.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ describe('CarouselComponent', () => {
tick(10);
expect(component).toBeTruthy();
}));

it('should resize work', fakeAsync(() => {
const myEvent = new Event('resize');
window.dispatchEvent(myEvent);
window.dispatchEvent(myEvent);
tick(200);
fixture.destroy();
}));

});

@Component({
Expand Down
12 changes: 12 additions & 0 deletions components/carousel/carousel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class CarouselComponent implements AfterViewInit, OnDestroy {
};

private _timer: any;
private _resizeTimer: any;
private _nodeArr: Array<any> = [];
private _lastIndex: number = 0;
private _isMouseDown: boolean = false;
Expand Down Expand Up @@ -172,6 +173,17 @@ export class CarouselComponent implements AfterViewInit, OnDestroy {
}, this.speed);
}

@HostListener('window:resize')
resize() {
if (this._resizeTimer) {
clearTimeout(this._resizeTimer);
}
this._resizeTimer = setTimeout(() => {
this.ngAfterViewInit();
clearTimeout(this._resizeTimer);
}, 200);
}

constructor(private _ele: ElementRef) {}

initCarouselSize() {
Expand Down

1 comment on commit 4ff06d9

@Guoyuanqiang
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

close #386

Please sign in to comment.