全宽 Swiper 在幻灯片左侧有一个间隙

SoK*_*KeT 5 javascript css swiper

大屏幕 Windows 版 Chrome 上的 Swiper 插件存在问题。它在幻灯片的左侧留下了空白,我创建了一支笔来演示这一点:

https://codepen.io/anon/pen/BwMxWX

HTML:

<div class="swiper-container">
  <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>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

.swiper-slide {
  width: 100vw;
  height: 300px;
}

.swiper-slide:nth-child(1) { background-color: lightpink; }
.swiper-slide:nth-child(2) { background-color: lightblue; }
.swiper-slide:nth-child(3) { background-color: lightgrey; }
Run Code Online (Sandbox Code Playgroud)

JS:

new Swiper(".swiper-container", {
  loop: true
});
Run Code Online (Sandbox Code Playgroud)

请记住,它只会在这些情况下发生。即使您在 Windows 上使用 Chrome,如果窗口大小小于(大约)2000 像素,那么它也不会发生。

在插件的主页上有一个全宽示例并且该问题不存在,但我并不真正理解首先是什么导致它发生。任何帮助将不胜感激。

更新:

我发现这只会在使用“幻灯片”效果时发生,这是默认设置。将其更改为任何其他修复它,但这远非解决方案。

小智 0

我首先尝试将 .swiper-slide 中的宽度更改为 100%。视图窗口和 % 不是一对一的。因此,100vw 并不等于 100%。这是参考页面:https://teamtreehouse.com/community/viewport-units-vs-percentages