Skip to content

Commit

Permalink
feat(module: carousel): feat when item=1 can not drag (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guoyuanqiang authored and fisherspy committed Jan 11, 2019
1 parent 8f772a9 commit 799ce51
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions components/carousel/carousel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class CarouselComponent implements AfterViewInit, OnDestroy {
private _currentSlideHeight: number = 0;
private _transition: string = '';
private _spaceWidth: number = 0;
private observer: MutationObserver;
private _observer: MutationObserver;
private _shouldDragging: boolean = true;

@ContentChildren(CarouselSlideComponent)
items: QueryList<CarouselSlideComponent>;
Expand Down Expand Up @@ -177,7 +178,8 @@ export class CarouselComponent implements AfterViewInit, OnDestroy {
carouselInit(items) {
this.infinite = this.infinite || true;
this._nodeArr = items['_results'];
this.dragging = this.dragging ? this.dragging : false;
this._shouldDragging = this._nodeArr.length > 1;
this.dragging = this.dragging ? this._shouldDragging : this.dragging;
if (this._nodeArr.length > 1) {
this._lastIndex = this._nodeArr.length - 1;
setTimeout(() => {
Expand Down Expand Up @@ -465,7 +467,8 @@ export class CarouselComponent implements AfterViewInit, OnDestroy {
this.carouselInit(items);
});
this.initCarouselSize();
this.getListStyles(-this.selectedIndex * this._rationWidth);
const index = this.items.length > 1 ? this.selectedIndex : 0;
this.getListStyles(-index * this._rationWidth);
this.carouselInit(this.items);
const nativeElement = this._ele.nativeElement;
const targetNode = nativeElement.querySelector('carouselslide');
Expand All @@ -475,19 +478,19 @@ export class CarouselComponent implements AfterViewInit, OnDestroy {
if (mutation.type == 'attributes') {
if (this.slideHeight !== nativeElement.querySelector('carouselslide').clientHeight) {
this.initCarouselSize();
this.getListStyles(-this.selectedIndex * this._rationWidth);
this.getListStyles(-index * this._rationWidth);
}
}
}
};

this.observer = new MutationObserver(callback);
this.observer.observe(targetNode, config);
this._observer = new MutationObserver(callback);
this._observer.observe(targetNode, config);
}

ngOnDestroy() {
this.observer.disconnect();
this.observer = null;
this._observer.disconnect();
this._observer = null;
this.stopTimer();
}
}

0 comments on commit 799ce51

Please sign in to comment.