如何自动旋转图像

时间:2015-08-05 05:23:23

标签: jquery html css

如何自动旋转图像?请检查我的小提琴,我试图在没有任何点击事件的情况下自动更改图像请查看这个小提琴:http://jsfiddle.net/hu3v8/1/

<div id="slider-code">
    <div class="viewport">
        <ul class="overview">
            <li><img src="http://www.baijs.nl/tinycarousel/images/picture3.jpg" /></li>
            <li><img src="http://www.baijs.nl/tinycarousel/images/picture2.jpg" /></li>
            <li><img src="http://www.baijs.nl/tinycarousel/images/picture1.jpg" /></li>
        </ul>
    </div>
    <a class="buttons next" id="nextButton" href="#">right</a>
</div>

4 个答案:

答案 0 :(得分:4)

http://baijs.com/tinycarousel/

您使用的tinycarousel插件已经提供了动画示例

请使用选项intervalintervalTime

&#13;
&#13;
$(function() {

  var current = 1;
  var totalImages = $("#slider-code li").size();
  var oSlider = $('#slider-code').tinycarousel({
    animation: true,
    controls: false,
    interval: true, // set interval option
    intervalTime: 1000 // 1 second
  });

  $('#nextButton').click(function() {
    current += 1;
    if (current > totalImages) {
      current = 1;
    }
    oSlider.tinycarousel_move(current);
  });
});
&#13;
#slider-code {
  height: 125px;
  overflow: hidden;
}
#slider-code .viewport {
  float: left;
  width: 240px;
  height: 125px;
  overflow: hidden;
  position: relative;
}
#slider-code .buttons {
  display: block;
  margin: 30px 10px 0 0;
  float: left;
}
#slider-code .next {
  margin: 30px 0 0 10px;
}
#slider-code .disable {
  visibility: hidden;
}
#slider-code .overview {
  list-style: none;
  position: absolute;
  padding: 0;
  margin: 0;
  left: 0;
  top: 0;
}
#slider-code .overview li {
  float: left;
  margin: 0 20px 0 0;
  padding: 1px;
  height: 121px;
  border: 1px solid #dcdcdc;
  width: 236px;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://baijs.com/tinycarousel/js/jquery.tinycarousel.js"></script>

<div id="slider-code">

  <div class="viewport">
    <ul class="overview">
      <li>
        <img src="http://www.baijs.nl/tinycarousel/images/picture3.jpg" />
      </li>
      <li>
        <img src="http://www.baijs.nl/tinycarousel/images/picture2.jpg" />
      </li>
      <li>
        <img src="http://www.baijs.nl/tinycarousel/images/picture1.jpg" />
      </li>
    </ul>
  </div>
  <a class="buttons next" id="nextButton" href="#">right</a>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:3)

&#13;
&#13;
$("#slideshow > div:gt(0)").hide();

setInterval(function() {
  $('#slideshow > div:first')
    .fadeOut(1000)
    .next()
    .fadeIn(1000)
    .end()
    .appendTo('#slideshow');
}, 3000);
&#13;
#slideshow {
  margin: 50px auto;
  position: relative;
  width: 240px;
  height: 240px;
  padding: 10px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);
}
#slideshow > div {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  bottom: 10px;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="slideshow">
  <div>
    <img src="//farm6.static.flickr.com/5224/5658667829_2bb7d42a9c_m.jpg">
  </div>
  <div>
    <img src="//farm6.static.flickr.com/5230/5638093881_a791e4f819_m.jpg">
  </div>

</div>
&#13;
&#13;
&#13;

答案 2 :(得分:3)

您可以尝试使用以下链接。

Fiddle

$("#slideshow > div:gt(0)").hide();

setInterval(function() {
    $('#slideshow > div:first')
        .fadeOut(1500)
        .next()
        .fadeIn(1500)
        .end()
        .appendTo('#slideshow');
}, 2000);

答案 3 :(得分:-1)

你的意思是这样的滑块吗?

Jssor Slider