我迫切需要有人帮助我让我的 CSS 滑块自动播放

I desperately need somebody to help me make my CSS slider autoplay

我只有这个 css 滑块,我需要让它自动播放。

我不太熟悉编码 javascript 所以这对我来说是一个相当具有挑战性的问题。

我知道必须为这段代码编写 Javascript will/may,但我想有人可以帮我澄清一下吗?

<div class="sliderContainer 6u">


  <ul class="slides">
    <input type="radio" name="radio-btn" id="img-1" checked />
    <li class="slide-container">
      <div class="slide">
        <img src="images/1.jpg" />
      </div>
      <div class="nav">
        <label for="img-6" class="prev">&#x2039;</label>
        <label for="img-2" class="next">&#x203a;</label>
      </div>
    </li>

    <input type="radio" name="radio-btn" id="img-2" />
    <li class="slide-container">
      <div class="slide">
        <img src="images/2" />
      </div>
      <div class="nav">
        <label for="img-1" class="prev">&#x2039;</label>
        <label for="img-3" class="next">&#x203a;</label>
      </div>
    </li>

    <input type="radio" name="radio-btn" id="img-3" />
    <li class="slide-container">
      <div class="slide">
        <img src="images/3.jpg" />
      </div>
      <div class="nav">
        <label for="img-2" class="prev">&#x2039;</label>
        <label for="img-4" class="next">&#x203a;</label>
      </div>
    </li>

    <input type="radio" name="radio-btn" id="img-4" />
    <li class="slide-container">
      <div class="slide">
        <img src="http://farm9.staticflickr.com/8061/8237246833_54d8fa37f0_z.jpg" />
      </div>
      <div class="nav">
        <label for="img-3" class="prev">&#x2039;</label>
        <label for="img-5" class="next">&#x203a;</label>
      </div>
    </li>

    <input type="radio" name="radio-btn" id="img-5" />
    <li class="slide-container">
      <div class="slide">
        <img src="http://farm9.staticflickr.com/8055/8098750623_66292a35c0_z.jpg" />
      </div>
      <div class="nav">
        <label for="img-4" class="prev">&#x2039;</label>
        <label for="img-6" class="next">&#x203a;</label>
      </div>
    </li>

    <input type="radio" name="radio-btn" id="img-6" />
    <li class="slide-container">
      <div class="slide">
        <img src="http://farm9.staticflickr.com/8195/8098750703_797e102da2_z.jpg" />
      </div>
      <div class="nav">
        <label for="img-5" class="prev">&#x2039;</label>
        <label for="img-1" class="next">&#x203a;</label>
      </div>
    </li>

    <li class="nav-dots">
      <label for="img-1" class="nav-dot" id="img-dot-1"></label>
      <label for="img-2" class="nav-dot" id="img-dot-2"></label>
      <label for="img-3" class="nav-dot" id="img-dot-3"></label>
      <label for="img-4" class="nav-dot" id="img-dot-4"></label>
      <label for="img-5" class="nav-dot" id="img-dot-5"></label>
      <label for="img-6" class="nav-dot" id="img-dot-6"></label>
    </li>
  </ul>

你能给我的任何帮助都会非常有帮助, 谢谢

由于您没有可提供的标记,我创建了这个:

示例片段(纯 css):

body {
  background: #eee;
  font-family: arial, helvetica, sans-serif;
  margin: 50px auto;
  padding: 0;
}
h1 {
  font-family: 'Proxima Nova', 'Helvetica Neue', sans-serif;
  font-size: 36px;
  text-align: center;
}
h3 {
  font-family: 'Proxima Nova', 'Helvetica Neue', sans-serif;
  font-size: 22px;
  font-style: italic;
  color: #4e4e4e;
  text-align: center;
  margin-bottom: -100px;
}
#wrapper {
  width: 400px !important;
  margin: 0 auto;
  overflow: hidden;
}
#wrapper {
  perspective: 2500;
  -webkit-perspective: 2500;
  width: 800px;
  margin: 200px auto 0 auto;
  perspective-origin: 50% 150px;
  -webkit-perspective-origin: 50% 150px;
  transition: perspective, 1s;
  -o-transition: -o-perspective, 1s;
  -moz-transition: -moz-perspective, 1s;
  -webkit-transition: -webkit-perspective, 1s;
}
#image:hover {
  animation-play-state: paused;
  -o-animation-play-state: paused;
  -moz-animation-play-state: paused;
  -webkit-animation-play-state: paused;
}
@-webkit-keyframes spin {
  from {
    transform: rotateY(0);
    -o-transform: rotateY(0);
    -ms-transform: rotateY(0);
    -moz-transform: rotateY(0);
    -webkit-transform: rotateY(0);
  }
  to {
    transform: rotateY(-360deg);
    -o-transform: rotateY(-360deg);
    -ms-transform: rotateY(-360deg);
    -moz-transform: rotateY(-360deg);
    -webkit-transform: rotateY(-360deg);
  }
}
#image {
  margin: 0 auto;
  height: 300px;
  width: 400px;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  animation: spin 24s infinite linear;
  -moz-animation: spin 24s infinite linear;
  -o-animation: spin 24s infinite linear;
  -webkit-animation: spin 24s infinite linear;
}
.image {
  position: absolute;
  height: 300px;
  width: 400px;
  border-radius: 25px;
  background-color: rgba(0, 0, 0, 0.6);
  text-align: center;
  font-size: 20em;
  color: #fff;
}
#image > .i1 {
  transform: translateZ(485px);
  -moz-transform: translateZ(485px);
  -o-transform: translateZ(485px);
  -ms-transform: translateZ(485px);
  -webkit-transform: translateZ(485px);
}
#image > .i2 {
  transform: rotateY(45deg) translateZ(485px);
  -moz-transform: rotateY(45deg) translateZ(485px);
  -o-transform: rotateY(45deg) translateZ(485px);
  -ms-transform: rotateY(45deg) translateZ(485px);
  -webkit-transform: rotateY(45deg) translateZ(485px);
}
#image > .i3 {
  transform: rotateY(90deg) translateZ(485px);
  -moz-transform: rotateY(90deg) translateZ(485px);
  -o-transform: rotateY(90deg) translateZ(485px);
  -ms-transform: rotateY(90deg) translateZ(485px);
  -webkit-transform: rotateY(90deg) translateZ(485px);
}
#image > .i4 {
  transform: rotateY(135deg) translateZ(485px);
  -moz-transform: rotateY(135deg) translateZ(485px);
  -o-transform: rotateY(135deg) translateZ(485px);
  -ms-transform: rotateY(135deg) translateZ(485px);
  -webkit-transform: rotateY(135deg) translateZ(485px);
}
#image > .i5 {
  transform: rotateY(180deg) translateZ(485px);
  -moz-transform: rotateY(180deg) translateZ(485px);
  -o-transform: rotateY(180deg) translateZ(485px);
  -ms-transform: rotateY(180deg) translateZ(485px);
  -webkit-transform: rotateY(180deg) translateZ(485px);
}
#image > .i6 {
  transform: rotateY(225deg) translateZ(485px);
  -moz-transform: rotateY(225deg) translateZ(485px);
  -o-transform: rotateY(225deg) translateZ(485px);
  -ms-transform: rotateY(225deg) translateZ(485px);
  -webkit-transform: rotateY(225deg) translateZ(485px);
}
#image > .i7 {
  transform: rotateY(270deg) translateZ(485px);
  -moz-transform: rotateY(270deg) translateZ(485px);
  -o-transform: rotateY(270deg) translateZ(485px);
  -ms-transform: rotateY(270deg) translateZ(485px);
  -webkit-transform: rotateY(270deg) translateZ(485px);
}
#image > .i8 {
  transform: rotateY(315deg) translateZ(485px);
  -moz-transform: rotateY(315deg) translateZ(485px);
  -o-transform: rotateY(315deg) translateZ(485px);
  -ms-transform: rotateY(315deg) translateZ(485px);
  -webkit-transform: rotateY(315deg) translateZ(485px);
}
img {
  border-radius: 25px;
<body>
  <h3>(hover over to pause)</h3>
  <div id="wrapper">
    <div id="image">
      <div class="image i1">
        <img src="https://dl.dropbox.com/u/80409395/Codepen/Noe-in-leaves.jpg">
      </div>
      <div class="image i2">
        <img src="https://dl.dropbox.com/u/80409395/Codepen/Nat-sitting.jpg">
      </div>
      <div class="image i3">
        <img src="https://dl.dropbox.com/u/80409395/Codepen/Nat-noodles.jpg">
      </div>
      <div class="image i4">
        <img src="https://dl.dropbox.com/u/80409395/Codepen/Charlie-smiling.jpg">
      </div>
      <div class="image i5">
        <img src="https://dl.dropbox.com/u/80409395/Codepen/Girls-in-leaves.jpg">
      </div>
      <div class="image i6">
        <img src="https://dl.dropbox.com/u/80409395/Codepen/Natalie-smiling.jpg">
      </div>
      <div class="image i7">
        <img src="https://dl.dropbox.com/u/80409395/Codepen/Charlie-sleeping.jpg">
      </div>
      <div class="image i8">
        <img src="https://dl.dropbox.com/u/80409395/Codepen/Sledding.jpg">
      </div>
    </div>
  </div>
</body>


我想提醒大家注意这个悬停状态:

#image:hover {
  animation-play-state: paused;
  -o-animation-play-state: paused;
  -moz-animation-play-state: paused;
  -webkit-animation-play-state: paused;
}

因为实际上是'pausing'动画。

我认为你应该研究 Javascript 的 setTimeout and SetInterval。 希望这有帮助。