Reputation: 3967
I have this function, and I'm trying to pass the wordtype
string variable back to the same function when it runs again.
Right now, except for the first time it runs (when I actually feed the string) - it shows undefined for wordtype
. I call it like this: rotateWordsA('nouns');
How can I make the rotateWordsA(wordtype);
actually pass the string back for the next round of animations?
i=0;
function rotateWordsA(wordtype){
console.log(wordtype);
var xyz = "#"+wordtype+" div."+i;
//console.log(xyz);
$("#"+wordtype+" div."+i).fadeOut(1000).hide();
//alert('hi');
i++;
//alert(i);
if($("#"+wordtype+" div."+i).length){
prev = i-1;
$("#"+wordtype+" div."+prev).fadeOut(1000).hide("slow");
$("#"+wordtype+" div."+i).fadeIn(1000).show();
$("#"+wordtype+" div."+i).delay(1000).animate({
//display: "show",
//left: "+=500",
opacity: 1
}, 1000, function(){
setTimeout(function(){rotateWordsA()}, 2500)
});
}
else{
i=0;
rotateWordsA(wordtype);
}
}
Upvotes: 0
Views: 56
Reputation: 133403
You are not passing variable to function call in setTimeout
setTimeout(function () {
rotateWordsA(); // Pass variable here
}, 2500)
Upvotes: 3