//wrap in a function to provide closure on following vars
//this will prevent them from being in the global scope and
//potentially colliding with other vars
(function () {
var sub = 0,
delay = 500, //500 ms = 1/2 a second
scrollScript = $('#scroll-script'),
slides = ['one', 'two', 'three', 'four'],
handle;
//calls the provided anonymous function at the interval delay
handle = setInterval(function () {
scrollScript.removeClass().addClass('slide-' + slides[sub]);
sub += 1;
// test to see if there is another class in the sequence of classes
if (!slides[sub]) {
//if not halt timed callback
clearInterval(handle);
}
}, delay);
}());
使其成为圆形:
//wrap in a function to provide closure on following vars
//this will prevent them from being in the global scope and
//potentially colliding with other vars
(function () {
var sub = 0,
delay = 500, //500 ms = 1/2 a second
scrollScript = $('#scroll-script'),
slides = ['one', 'two', 'three', 'four'],
handle;
//calls the provided anonymous function at the interval delay
handle = setInterval(function () {
scrollScript.removeClass().addClass('slide-' + slides[sub % slides.length]);
sub += 1;
}, delay);
}());