如何让这个滑块自动播放?

时间:2014-07-16 06:47:33

标签: javascript jquery html5 css3

我已从此Site下载滑块 我试图让这个Slider自动播放,但我似乎无法让它发挥作用,有谁知道我是如何实现这一目标的?我尝试使用下面的代码,但无法得到我想要的东西。

 function init() {
    [].forEach.call(document.querySelectorAll('.tt-grid-wrapper'), function (el) {

        var grid = el.querySelector('.tt-grid'),
            items = [].slice.call(grid.querySelectorAll('li')),
            navDots = [].slice.call(el.querySelectorAll('nav > a')),
            isAnimating = false,
            current = 0;

        navDots.forEach(function (el, i) {
            el.addEventListener(eventtype, function (ev) {
                if (isAnimating || current === i) return false;
                ev.preventDefault();
                isAnimating = true;
                updateCurrent(i);
                loadNewSet(i);
            });
        });

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情:

 function init() {
    [].forEach.call(document.querySelectorAll('.tt-grid-wrapper'), function (el) {

        var grid = el.querySelector('.tt-grid'),
            items = [].slice.call(grid.querySelectorAll('li')),
            navDots = [].slice.call(el.querySelectorAll('nav > a')),
            isAnimating = false,
            current = 0;

        navDots.forEach(function (el, i) {
            el.addEventListener(eventtype, function (ev) {
                if (isAnimating || current === i) return false;
                ev.preventDefault();
                isAnimating = true;
                updateCurrent(i);
                loadNewSet(i);
            });
        });

        var delay = 1000;
        var num_frames = 4;
        var i = 1;

        setTimeout( function() { 
            if (isAnimating || current === i) return false;
            isAnimating = true;
            updateCurrent(i);
            loadNewSet(i);
            i >= 4 ? i = 0 : i++;
        } , delay);
};