You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swiper持续自动滚动卡顿求助:需平滑滚动+鼠标悬停暂停

Swiper 10.0.2 平滑循环滚动问题解决

你的问题出在配置参数组合和CSS过渡设置上,以下是具体修正方案:

核心问题分析

  1. autoplay.waitForTransition: true会让Swiper等待当前滚动过渡完成后再触发下一次滚动,导致出现停顿间隙
  2. freeMode.momentum默认开启,会让滚动产生惯性,出现减速/加速的波动
  3. CSS过渡函数没有正确作用在滚动容器上
  4. autoplay.delay:1仍存在极小间隔,无法实现完全连续滚动

修正后的完整代码

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>Swiper demo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" />
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@10/swiper-bundle.min.css" />
  <style>
    html,
    body {
      position: relative;
      height: 100%;
    }

    body {
      background: #eee;
      font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
      font-size: 14px;
      color: #000;
      margin: 0;
      padding: 0;
    }

    .swiper {
      width: 100%;
      height: 100%;
    }

    /* 关键:给滚动容器设置线性过渡 */
    .swiper-wrapper {
      transition-timing-function: linear !important;
    }

    .swiper-slide {
      text-align: center;
      font-size: 18px;
      background: red;
      display: flex;
      justify-content: center;
      align-items: center;
      max-width: 660px;
    }

    .swiper-slide img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  </style>
</head>
<body>
  <div class="swiper mySwiper">
    <div class="swiper-wrapper">
      <div class="swiper-slide">Slide 1</div>
      <div class="swiper-slide">Slide 2</div>
      <div class="swiper-slide">Slide 3</div>
      <div class="swiper-slide">Slide 4</div>
      <div class="swiper-slide">Slide 5</div>
      <div class="swiper-slide">Slide 6</div>
      <div class="swiper-slide">Slide 7</div>
      <div class="swiper-slide">Slide 8</div>
      <div class="swiper-slide">Slide 9</div>
    </div>
  </div>

  <script src="https://cdn.jsdelivr.net/npm/swiper@10/swiper-bundle.min.js"></script>
  <script>
    var swiper = new Swiper(".mySwiper", {
      spaceBetween: 40,
      loop: true,
      slidesPerView: "auto",
      speed: 8000, // 调整数值控制滚动速度,越大越慢
      freeMode: {
        enabled: true,
        momentum: false, // 关闭惯性,保持匀速
      },
      autoplay: {
        delay: 0, // 无间隔,持续滚动
        pauseOnMouseEnter: true,
        disableOnInteraction: false,
        waitForTransition: false, // 不等待过渡结束,连续滚动
        stopOnLastSlide: false,
      }
    });
  </script>
</body>
</html>

关键参数说明

  • autoplay.delay: 0:取消滚动间隔,实现无缝连续滚动
  • autoplay.waitForTransition: false:禁止等待过渡完成,避免停顿
  • freeMode.momentum: false:关闭自由模式的惯性,保持匀速
  • .swiper-wrapper { transition-timing-function: linear !important; }:强制滚动过渡为线性,确保速度恒定

内容的提问来源于stack exchange,提问作者probablybest

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 01:57:52