Reputation: 5513
I want to replace the text in a 'div span' with text from an array. I'd like this simple animation to do two things...
I have a fiddle setup where I've been trying different things; http://jsfiddle.net/fmdfrank/W47QV/
Anybody?
Upvotes: 3
Views: 5144
Reputation: 645
use jquery .queue & .dequeue to store each operation in the fx queue. this will let the text change behave as part of the animation queue. then check if you need to loop.
in a fiddle: http://jsfiddle.net/W47QV/4/
$(document).ready(function() {
var items = ["Two", "Three", "Four", "Five", "Six", "One"],
$text = $( '#div1 span' ),
delay = 2; //seconds
function loop ( delay ) {
$.each( items, function ( i, elm ){
$text.delay(delay*1E3).fadeOut();
$text.queue(function(){
$text.html( items[i] );
$text.dequeue();
});
$text.fadeIn();
$text.queue(function(){
if(i == items.length-1){
loop(delay);
}
$text.dequeue();
});
});
}
loop(delay);
});
Upvotes: 5