Here is the simple jquery to rotate array of strings
$.fn.loadText = function( textArray, interval ) {
return this.each( function() {
var obj = $(this);
obj.fadeOut( 'slow', function() {
obj.empty().html( random_array( textArray ) );
obj.fadeIn( 'slow' );
});
timeOut = setTimeout( function(){ obj.loadText( textArray, interval )}, interval );
if( !obj.is(':animated') ) { clearTimeout( timeOut ); obj.loadText( textArray, interval );}
});
}
function random_array( aArray ) {
var rand = Math.floor( Math.random() * aArray.length + aArray.length );
var randArray = aArray[ rand - aArray.length ];
return randArray;
}
$(document).ready( function() {
var textArray = ["murali","prashanth","nutal","candy"];
$('#mydiv').loadText( textArray, 5000 );
});
Here is the problem, Newly generated random number should not be the same one as previously generated it should be new number so that the array of strings should not repeat again.Let's say if murali
is generated then again murali
should not generate may be other string should be displayed from array.Please help