我有这段脚本,但我无法弄清楚如何成功删除随机函数,以便数组一次流过每个数组项,而不是随机显示每个项。
$(window).ready(function() {
var helloArray = ["hello", "bonjour", "hola", "konnichiwa", "hujambo", "czesc", "hei", "ciao"];
$('#page_title').loadText( helloArray, 5000 ); // ( array, interval )
});
$.fn.loadText = function( textArray, interval ) {
return this.each( function() {
var obj = $(this);
obj.fadeOut( 'slow', function() {
obj.empty().html( random_array( textArray ) );
obj.fadeIn( 'fast' );
});
timeOut = setTimeout( function(){
obj.loadText( textArray, interval )
}, interval );
$("#text-reload").click( function(){
if( !obj.is(':animated') ) {
clearTimeout( timeOut );
// animation check prevents "too much recursion" error in jQuery
obj.loadText( textArray, interval );
}
});
});
}
//public function
function random_array( aArray ) {
var rand = Math.floor( Math.random() * aArray.length + aArray.length );
console.log(randArray);
var randArray = aArray[ rand - aArray.length ];
return randArray;
}