Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

jQuery Slider without stopping

jQuery Slider without stopping

Problem

I'm making a Jquery Slider using sliced images to look like one looong sliding banner:

Example: http://jsfiddle.net/pG8kt/66/

Two issue I'm having:

1) The third image in the sequence loads too late

2) It stops between slides - but I don't want it too

Any ideas why? Thanks :)

Problem courtesy of: Dave

Solution

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();

Updated with everything and stuff...

Solution courtesy of: Simon

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

jQuery Slider without stopping

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×