I have what I thought was a simple javascript / jquery function (disappear from one div, disappear into another ... loop until it reaches its maximum and then starts from the very beginning. Fadein of the next div I need to increase the global counter. By doing this is doubled in increments, because I assume that the local variable I created supports the same reference to the global variable.
Below is the sample code below. Can someone determine what I am doing wrong?
var current_index = 1;
$(document).ready(function() {
$(function() {
setInterval("selectNextStep()", 3000);
});
});
function selectNextStep() {
$("#step_"+current_index).fadeOut('slow', function() {
var next = current_index;
next = next + 1;
$("#step_"+next).fadeIn('slow', function() {
if (current_index == 4) current_index = 1;
else current_index ++;
});
});
}
source
share