1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| var timer = new Object;
function slider(){
nextSlide();
timer = window.setTimeout(slider,5000);
}
function nextSlide(){
var $Slides = $("#slides");
$("#nextSlide").unbind("click",nextSlide);
$Slides.animate(
{marginLeft:"-=1600px"},
500,
function(){
$Slides.data("currentSlide",$Slides.data("currentSlide")+1);
if($Slides.data("currentSlide") > $Slides.data("nbSlides")){
$Slides
.data("currentSlide",1)
.css({marginLeft:"-1600px"});
}
window.clearTimeout(timer);
timer = window.setTimeout(slider,5000);
$("#nextSlide").bind("click",nextSlide);
}
);
}
function prevSlide(){
var $Slides = $("#slides");
$("#prevSlide").unbind("click",prevSlide);
$Slides.animate(
{marginLeft:"+=1600px"},
500,
function(){
$Slides.data("currentSlide",$Slides.data("currentSlide")-1);
if($Slides.data("currentSlide") == 0){
$Slides
.data("currentSlide",$Slides.data("nbSlides"))
.css({marginLeft:-(1600*$Slides.data("currentSlide"))});
}
window.clearTimeout(timer);
timer = window.setTimeout(slider,5000);
$("#prevSlide").bind("click",prevSlide);
}
);
}
$(function(){
var $Slides = $("#slides");
var _step = $Slides.find("li:first").width();
$Slides
.data("currentSlide",1)
.data("nbSlides",$Slides.find("li").size());
$Slides
.find("li:last")
.clone()
.prependTo("#slides");
$Slides
.find("li:first")
.next()
.clone()
.appendTo("#slides");
$Slides
.find("li:first")
.addClass("clone")
.end()
.find("li:last")
.addClass("clone")
.end()
.css({marginLeft:-_step});
$Slides.width($Slides.find("li").size()*_step);
$("#nextSlide").bind("click",nextSlide);
$("#prevSlide").bind("click",prevSlide);
timer = window.setTimeout(slider,5000); |
Partager