angular - Swiper 自动播放在 Angular 中不起作用(单张幻灯片)

我正在使用带 Angular (v 12) 的 swiperjs,我想为每张幻灯片设置特定的延迟。 我从“swiper/core”导入了 {Autoplay} 并调用了方法 SwiperCore.use([Autoplay])。 如果我为所有幻灯片设置延迟,效果很好:

// .ts component
import SwiperCore, { Autoplay } from 'swiper'

SwiperCore.use([Autoplay])

autoplay: AutoplayOptions | boolean = {
  delay: 3000,
  disableOnInteraction: false
}
// .Html 
<swiper
  #swiperSlideShow
  [slidesPerView]="1"
  [spaceBetween]="50"
  (swiper)="onSwiper($event)"
  (slideChange)="onSlideChange()"

  [loop]="true"
  [autoplay]="true"
  [effect]="'coverflow'"
  [coverflowEffect]="coverflowEffect"

  [parallax]="true"
  [keyboard] = "keyboard"
  [speed]="1800"
>

  <ng-template swiperSlide >
    <div >
        <app-slide-three></app-slide-three>
    </div>
     <div >
        <app-slide-ex></app-slide-ex>
    </div>
    <div >
        <app-slide-dy></app-slide-dy>
    </div>

  </ng-template>

但是 'data-swiper-autoplay' 被忽略并且 <ng-template swiperSlide data-swiper-autoplay="5000" >保留延迟的默认值 (3000),我不知道是否有特定的 Angular 方法将此延迟分配给单个幻灯片,在文档中未指定..

最佳答案

我可以找到一个方法,试试这个:

.HTML:

<swiper class="mySwiper" 
[autoplay]= "{
delay: 1000*items[0].duration
}"
(slideChange)="onSlideChange($event)">
  <ng-template swiperSlide *ngFor="let item of items">
    <div class="content">{{item.title}}</div>
  </ng-template>
</swiper>

.ts:

onSlideChange(swiper: any) {
swiper.params.autoplay.delay = 1000*this.items[swiper.realIndex].duration;}

https://stackoverflow.com/questions/68111687/

相关文章:

c++ - 尝试将函数作为参数传递时出现 "no suitable constructor exis

linux - 如何从第二行使用 awk '{print $1*Number}' 或告诉他忽略 Na

python - 为什么使用聚合来查找平均值而不是在 django 中使用 tutal_sum/n

node.js - 如何对类型关系进行递归

android - 使用导航组件为每个 fragment 自定义工具栏

python - 如何在 python 中从 json 获取输入的随机回复

python - 如何删除 requirements.txt 中不需要的路径?

kubernetes - 无法使用 Terraform 为 AKS 集群创建命名空间,报告没有此类主

reactjs - "Did not retain recoil value on render,

node.js - 如何使用 cmd 更新 Node.js?