jQuery Slider没有停止

时间:2012-06-29 11:52:55

标签: jquery css3

我正在制作一个jQuery滑块,使用切片图像看起来像一个looong滑动横幅:

示例:http://jsfiddle.net/pG8kt/66/

我有两个问题:

1)序列中的第三张图片加载太晚

2)它在幻灯片之间停止 - 但我也不想要它

任何想法为什么?谢谢:))

1 个答案:

答案 0 :(得分:2)

http://jsfiddle.net/pG8kt/76/

var showing = 0, // current img
    imgs = [], // all imgs
    $img = $("#gallery img"), // jQuery DOM object
    imgWidth = $img.outerWidth(), // img width assuming every img has same
    $slider = $("#slider"),
    $title = $("#title");

imgs = $img.toArray();
  // Variable to store number of images
var numberOf = imgs.length;
  // set slider width so floated elements line up
$slider.width(numberOf*imgWidth);

  // Recursive next image function
var nextImage = function() {
    var $nextImg = $(imgs[showing++ % numberOf]);
      // Add next image (only use increment once!)
    $slider.append($nextImg);
      // Show image title
    $title
        .html($nextImg.attr("title"))
        .attr("href", $nextImg.attr("src"));        
      // Animate the slider
    $slider.animate({
        left: '-='+imgWidth
    }, 8000, 'linear', function() {
          // Reset CSS
        $slider.css("left", 0);            
          // Call animationg function again
        nextImage();
    });  
}        
  // Call next image for the first time
nextImage();

更新了所有内容......