在这里我有一个问题,我想做一个滑块,我window.clearTimeout(timer)
在函数nextSlide()
和prevSlide()
. 你能帮助我吗 ?
var timer = new Object;
function slider(){
nextSlide();
window.setTimeout(slider, 5000);
}
function nextSlide(){
var $Slides = $(".contenu");
$Slides.animate(
{left: "-=213px"},
1000,
function(){
$Slides.data("currentSlide",$Slides.data("currentSlide")+1);
if($Slides.data("currentSlide") > $Slides.data("nbSlides")) {
$Slides.data("currentSlide",1).css({left:"-213px"});
}
}
window.clearTimeout(timer);
timer = window.setTimeout(slider, 5000);
);
}
function prevSlide(){
var $Slides = $(".contenu");
$Slides.animate(
{left:"+=213px"},
1000,
function(){
$Slides.data("currentSlide", $Slides.data("currentSlide")-1);
if($Slides.data("currentSlide") == 0) {
$Slides.data("currentSlide",$Slides.data("nbSlides")).css({left:-(213*$Slides.data("currentSlide"))});
}
}
window.clearTimeout(timer);
timer = window.setTimeout(slider, 5000);
);
}
这里加载:
$(function(){
slider();
$('#slider').addClass('slider');
var $Slides = $('.contenu');
var _step = $Slides.find(".slide:first").width();
$Slides.data("currentSlide",1).data("nbSlides",$Slides.find('.slide').size());
$Slides.find(".slide:last").clone().prependTo(".contenu");
$Slides.find(".slide:first").next().clone().appendTo('.contenu');
$Slides.find(".slide:first").addClass("clone").end().css({left:-_step});
$Slides.width($Slides.find(".slide").size()*_step);
$('.next').bind("click", nextSlide);
$('.prev').bind("click", prevSlide);
});
谢谢帮助。;)