需要为图像轮播添加计时器

时间:2014-01-15 06:19:58

标签: jquery performance carousel

我目前有一个可导航的图像轮播,但我想添加一个定时器,可以在5秒内自动旋转幻灯片。非常感谢任何建议!

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"> </script>  
  <script>
 var current_slide = 0; // zero-based
 var slide_count = 12;
 var slide_size = 725;

 var Direction = {
  LEFT: -1,
  RIGHT: 1
 };

 /**
 * Moves to the next slide using the direction (dx) parameter.
 */
 var nextSlide = function(dx) {
  current_slide = (current_slide + slide_count + dx) % slide_count;

  // Calculate the new value for css 'left' property and animate.
  var left_offset = '-' + (current_slide * slide_size) + 'px';
  $('.items').animate({'left': left_offset}, 300);
 };

 $('.right-button').click(nextSlide.bind(null, Direction.RIGHT));
 $('.left-button').click(nextSlide.bind(null, Direction.LEFT));


 $('.carousel').show();
 $(document).ready(function() {
         $('.carousel').carousel({
             interval: 2000
         })
    }); 
</script>

0 个答案:

没有答案