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

时间:2015-01-19 11:46:18

标签: javascript jquery css slider autoplay

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

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

我知道Javascript将/可能必须为此代码编写,但我认为那里有人可以帮我澄清一下这个问题?



<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>
&#13;
&#13;
&#13;

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

2 个答案:

答案 0 :(得分:1)

由于您提供无标记,我已经创建了这个:

示例代码段(纯css):

&#13;
&#13;
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;
&#13;
<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>
&#13;
&#13;
&#13;


我想提请注意这个悬停状态:

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

因为实际上是暂停&#39;动画。

答案 1 :(得分:0)

我认为你应该研究Javascript的setTimeoutSetInterval。 希望这会有所帮助。