滑块自动播放

时间:2014-02-19 12:21:56

标签: jquery

我有一个滑块,到目前为止效果非常好。但现在我仍然需要一个自动播放,并且还没有得到如何实现这一点的线索。有人有想法吗?

var current = 1;
var wDoc = $(document).width();
var box = $(".bg-box");
var boxLength = box.length + 2;
var clipUl = $('.clip ul');
var speedAnimation = 1000;
function slideBox(to) {
    if (to < 0) {
        clipUl.css('left', -((boxLength - 2) * wDoc));
        to = boxLength - 3;
    } else if (to > (boxLength - 1)) {
        clipUl.css('left', -(1 * wDoc));
        to = 2;
    }
    clipUl.stop().animate({
        left: -(to * wDoc)
    }, speedAnimation);
    current = to;
    currentNum = current;
    $('.pagging-box').removeClass('active');
    if (to > (boxLength - 2)) {
        currentNum = 1;
    }
    if (to == 0) {
        currentNum = boxLength - 2;
    }
    $('#pagg' + currentNum).addClass('active');

};

1 个答案:

答案 0 :(得分:0)

试试这个:

var startAutoPlay = function() {
    var time = 2000; // (2 seconds);
    current = 0;
    setInterval(function(){
        slideBox(current);
        current += 1;
    }, time);
}

startAutoPlay();