I am trying to make a Javascript that loops infinitly.
function scroll(num) {
$("." + num + "").fadeOut('slow');
var choose = num + 1;
$("." + choose + "").fadeIn('slow');
setTimeout(function() {
scroll(choose);
}, 1000);
}
setTimeout(function() {
scroll('1');
}, 1000);
It does the function the first time but does not continue.
Please help!
You’re using one as both a string and as an integer: Calling
scroll('1')means thatnum + 1will return"11", not2as you expect. Try this instead: