angular n’g-zorro走马灯划过时如何停止切换
在写项目时,我用到了ng-zorro这个控件,后来经理想在鼠标划过时能停止swipper自动切换,我想了一下
,最后发现zorro的走马灯有一个[nzAutoPlay]属性可以直接控制是否切换,话不多说,直接上代码:
<div class=" bottomLeft" #myCarousel>
<nz-carousel [nzEffect]="'scrollx'" [nzAutoPlay]="carouselPlay" [nzAutoPlaySpeed]="'5000'" #zd>
<div nz-carousel-content *ngFor="let table of stationData">
<div class="tabContain">
<p class="date-place">
<span>2018年8月24日 星期五 </span>
</p>
</div>
</nz-carousel>
</div>
import { Observable, observable } from 'rxjs';
@ViewChild('myCarousel') myCarouselEle: ElementRef;
carouselPlay = true;
ngAfterViewInit() {
this.carouselPlay = true;
let mouseover = Observable.fromEvent(this.myCarouselEle.nativeElement, 'mouseover');
mouseover.subscribe(() => {
this.stopCarousel();
});
let mouseleave = Observable.fromEvent(this.myCarouselEle.nativeElement, 'mouseleave');
mouseleave.subscribe(() => {
this.autoCarousel();
});
}
stopCarousel() {
this.carouselPlay = false;
}
autoCarousel() {
this.carouselPlay = true;
}