我在我的项目中使用了离子幻灯片。代码如下:
<ion-grid class="ion-margin-left">
<ion-slides [options]="slideConfig">
<ion-slide *ngFor="let item of items">
<ion-card style="margin-right: 2px">
<div class="img-container">
<img src="/assets/contents/gif_icon/{{item.imgName}}" class="img-style">
</div>
<ion-card-content>
<p>{{item.title}}</p>
</ion-card-content>
</ion-card>
</ion-slide>
</ion-slides>
</ion-grid>
在使用slideConfig
options之前,幻灯片运行良好autoplay: true
。幻灯片配置选项代码如下。
this.slideConfig = {
slidesPerView: window.innerWidth / 140,
autoplay: true
};
@HostListener('window:resize', ['$event'])
onResize(event) {
this.slideConfig = {
slidesPerView: window.innerWidth / 140,
autoplay: true
};
}
问题主要发生在我旋转屏幕时。我正在尝试显示宽度为 120 像素的卡片。即使在旋转之后,哪个始终是 120 像素?旋转卡前滑动正常,但旋转后卡滑动太快。那么我该如何解决这个问题呢?
请注意一件事,每当我旋转slidesPerView
意志时dynamic
。例如,在portrait
模式中slidesPerView
可能是3
针对device
. 对于同一设备,如果用户旋转设备,则slidesPerView
可能是 5。为了实现这一点,我使用了@HostListener('window: resize')
功能。但是如果我在模式下加载项目,portrait
那么如果我旋转设备然后autoplay
滑动一点点快。我知道问题的发生是因为slidesPerView
是动态的。但我不能同时修复slidesPerView
幻灯片需要自动播放。我怎样才能做到这一点?