html - 使用 CSS-HTML 的幻灯片仅显示四张幻灯片

标签 html css slideshow

我正在使用幻灯片,我只使用 css 和 HTML。我总共使用了六张幻灯片,但它只显示了四张幻灯片。它不会移动到第 5 位和第 6 位。我不明白我在哪里犯了错误,请纠正我。

问题:https://jsfiddle.net/usm10hfy/

您可以在 JsFiddle 上看到我面临的问题。希望您有所帮助,在此先感谢。

<style>
body {
  font-family: Helvetica, sans-serif;
  padding: 5%;
  text-align: center;
}

#slideshow {
  overflow: hidden;
  height: 510px;
  width: 728px;
  margin: 0 auto;
}

.slide-wrapper {
  width: 2912px;
  -webkit-animation: slide 18s ease infinite;
}

.slide {
  float: left;
  height: 510px;
  width: 728px;
}

.slide:nth-child(1) {
  background: #D93B65;
}

.slide:nth-child(2) {
  background: #037E8C;
}

.slide:nth-child(3) {
  background: #36BF66;
}

.slide:nth-child(4) {
  background: #D9D055;
}

.slide:nth-child(5) {
  background: #D9D055;
}

.slide:nth-child(6) {
  background: #D9D055;
}

.slide-number {
  color: #000;
  text-align: center;
  font-size: 10em;
}

@-webkit-keyframes slide {
  20% {margin-left: 0px;}
  30% {margin-left: -728px;}
  50% {margin-left: -728px;}
  60% {margin-left: -1456px;}
  70% {margin-left: -1456px;}
  80% {margin-left: -2184px;}
  90% {margin-left: -2184px;}
}
</style>

<div id="slideshow">
  <div class="slide-wrapper">
    <div class="slide"><h1 class="slide-number">1</h1></div>
    <div class="slide"><h1 class="slide-number">2</h1></div>
    <div class="slide"><h1 class="slide-number">3</h1></div>
    <div class="slide"><h1 class="slide-number">4</h1></div>
    <div class="slide"><h1 class="slide-number">5</h1></div>
    <div class="slide"><h1 class="slide-number">6</h1></div>
  </div>
</div>

最佳答案

body {
  font-family: Helvetica, sans-serif;
  padding: 5%;
  text-align: center;
}

#slideshow {
  overflow: hidden;
  height: 510px;
  width: 728px;
  margin: 0 auto;
}

.slide-wrapper {
  width: 4368px; /*change this width */
  -webkit-animation: slide 10s ease infinite;
}

.slide {
  float: left;
  height: 510px;
  width: 728px;
}

.slide:nth-child(1) {
  background: #D93B65;
}

.slide:nth-child(2) {
  background: #037E8C;
}

.slide:nth-child(3) {
  background: #36BF66;
}

.slide:nth-child(4) {
  background: #D9D055;
}

.slide:nth-child(5) {
  background: #D9D055;
}

.slide:nth-child(6) {
  background: #D9D055;
}

.slide-number {
  color: #000;
  text-align: center;
  font-size: 10em;
}

@-webkit-keyframes slide {  /* add keyframe animations to move each slide towards left */
  15% {margin-left: 0px;}
  30% {margin-left: -728px;}
  45% {margin-left: -1456px;}
  60% {margin-left: -2184px;}
  75%{margin-left: -2912px;}
  90%{margin-left: -3640px;}

}

现在它工作正常:https://jsfiddle.net/4othdxg7/

演示:

body {
  font-family: Helvetica, sans-serif;
  padding: 5%;
  text-align: center;
}

#slideshow {
  overflow: hidden;
  height: 510px;
  width: 728px;
  margin: 0 auto;
}

.slide-wrapper {
  width: 8736px;
  -webkit-animation: slide 12s ease infinite;
}

.slide {
  float: left;
  height: 510px;
  width: 728px;
}

.slide:nth-child(1) {
  background: #D93B65;
}

.slide:nth-child(2) {
  background: #037E8C;
}

.slide:nth-child(3) {
  background: #36BF66;
}

.slide:nth-child(4) {
  background: #D9D055;
}

.slide:nth-child(5) {
  background: red;
}

.slide:nth-child(6) {
  background: #D9D055;
}

.slide:nth-child(7) {
  background: #D93B65;
}

.slide:nth-child(8) {
  background: #037E8C;
}

.slide:nth-child(9) {
  background: #36BF66;
}

.slide:nth-child(10) {
  background: #D9D055;
}

.slide:nth-child(11) {
  background: red;
}

.slide:nth-child(12) {
  background: #D9D055;
}

.slide-number {
  color: #000;
  text-align: center;
  font-size: 10em;
}

@-webkit-keyframes slide {
  8% {
    margin-left: 0px;
  }
  16% {
    margin-left: -728px;
  }
  24% {
    margin-left: -1456px;
  }
  32% {
    margin-left: -2184px;
  }
  40% {
    margin-left: -2912px;
  }
  48% {
    margin-left: -3640px;
  }
  56% {
    margin-left: -4368px;
  }
  64% {
    margin-left: -5096px;
  }
  72% {
    margin-left: -5824px;
  }
  80% {
    margin-left: -6552px;
  }
  88% {
    margin-left: -7280px;
  }
  100% {
    margin-left: -8008px;
  }
}
<div id="slideshow">
  <div class="slide-wrapper">
    <div class="slide">
      <h1 class="slide-number">1</h1>
    </div>
    <div class="slide">
      <h1 class="slide-number">2</h1>
    </div>
    <div class="slide">
      <h1 class="slide-number">3</h1>
    </div>
    <div class="slide">
      <h1 class="slide-number">4</h1>
    </div>
    <div class="slide">
      <h1 class="slide-number">5</h1>
    </div>
    <div class="slide">
      <h1 class="slide-number">6</h1>
    </div>
    <div class="slide">
      <h1 class="slide-number">7</h1>
    </div>

    <div class="slide">
      <h1 class="slide-number">8</h1>
    </div>
    <div class="slide">
      <h1 class="slide-number">9</h1>
    </div>
    <div class="slide">
      <h1 class="slide-number">10</h1>
    </div>
    <div class="slide">
      <h1 class="slide-number">11</h1>
    </div>
    <div class="slide">
      <h1 class="slide-number">12</h1>
    </div>

  </div>
</div>

关于html - 使用 CSS-HTML 的幻灯片仅显示四张幻灯片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59495336/

相关文章:

html - 如何防止 DIV 与右侧 float 图像重叠?

Javascript 图像幻灯片放映循环

javascript - 制作 Javascript 简单的幻灯片

javascript - 在html页面上画线

javascript - Html 包含 jQuery

css - Wordpress 在自定义侧边栏上丢失了填充

html - 列表元素的背景图片不会在 Chrome 中显示

html - 隐藏的溢出不适用于固定子项

css - 从左到右的虚线边框(两个元素之间)

javascript - 响应式幻灯片无法正常工作