简体   繁体   中英

Make a Javascript slider auto-slide every 4 seconds

I am using Prism Effect Slider, source: http://tympanus.net/codrops/2015/03/31/prism-effect-slider-canvas/

I am trying to make it slide automatically every 4 seconds

Live version here: http://codepen.io/jdesign/pen/zqXxVr

Prism Effect Slider

Your example on codepen is not working. Here is how you can do it. Just add this to slideshow.js at the bottom before return:

var index = 0;
setInterval(slideLoop, 4000);

function slideLoop() { 
    if (index >= slides.length) index = 0;
    slideAllTo_(index);
    // change bullet
    for (var i = 0; i < navigation.element.childNodes.length; i++) {
        if (i === index) {
            navigation.element.childNodes[i].className = navigation.attrs.active;
        } else {
            navigation.element.childNodes[i].className = '';
        }
  }
    index++;
}

A quick look at the documentation suggests that you can do it by setting the duration global variable:

/**
 * Set global duration.
 * @type {Number}
 */
var duration = 4000;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM