Swiper持续自动滚动卡顿求助:需平滑滚动+鼠标悬停暂停
Swiper 10.0.2 平滑循环滚动问题解决
你的问题出在配置参数组合和CSS过渡设置上,以下是具体修正方案:
核心问题分析
autoplay.waitForTransition: true会让Swiper等待当前滚动过渡完成后再触发下一次滚动,导致出现停顿间隙freeMode.momentum默认开启,会让滚动产生惯性,出现减速/加速的波动- CSS过渡函数没有正确作用在滚动容器上
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
相关产品推荐
相关产品推荐

