简体   繁体   English

自动播放幻灯片不适用于 Swiper JS

[英]AutoPlay Slides not working for Swiper JS

I am currently working with svelte to create a smooth auto slider using SwiperJs.我目前正在与 svelte 一起使用 SwiperJs 创建一个平滑的自动 slider。 It seems that I am unable to create that animation.看来我无法创建 animation。 When loading the page, the autoPlay dosen't seem to work.加载页面时,自动播放似乎不起作用。 Below is the add-ons that got me to this:以下是让我这样做的附加组件:

<Swiper 
slidesPerView={2}
autoplay={{
    delay: 1,
    disableOnInteraction: false,
}}
speed={5000}
loop={true}
pagination={{
  clickable: true,
}}
navigation={true}
modules={[Autoplay, Pagination, Navigation]}
>

The contents in 3 slides are with different object reffered each time. 3张幻灯片中的内容每次引用不同的object。

<SwiperSlide >
  <div class="workGridContainer">
    {#each workLinks as work}
      <div class="workCell {work.id}">
        <img class="workImg" src={work.imageLink} alt={work.id} />
        <h2 class="gridTitle">{work.title}</h2>
        <p>{work.description}</p>
        <a href={work.source} target="blank">Visit</a>
      </div>
    {/each}
 </div>
<SwiperSlide />

And I am Importing Modules such as我正在导入模块,例如

import { Swiper, SwiperSlide }from "swiper/svelte";
import { Autoplay, Pagination, Navigation } from "swiper";

I see that you are giving a delay of 1. But the delay is given in milliseconds, so you are basically trying to play the Swiper each millisecond, which is obviously too fast.我看到你给出的延迟是 1。但是延迟是以毫秒为单位给出的,所以你基本上是在尝试每毫秒播放一次 Swiper,这显然太快了。

If you want it to play each second, then you should write 1000 instead of 1:如果你希望它每秒播放一次,那么你应该写 1000 而不是 1:

<Swiper 
  slidesPerView={2}
  autoplay={{
    delay: 1000,
    disableOnInteraction: false,
  }}
  speed={5000}
  loop={true}
  pagination={{
  clickable: true,
  }}
  navigation={true}
  modules={[Autoplay, Pagination, Navigation]}
>

I hope this helps you!我希望这可以帮助你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM