News scroller with array

by ajinkyax

HTML

<div id="ticker"></div>

CSS

#ticker {
    font-size: 11px;
    padding: 4px;
}

JavaScript

$(document).ready(function () {
    createTicker();
});
 
function createTicker(){
    //set the quotes array
    tickerItems = new Array(
    '"There are no great men, only great challenges that ordinary men are forced by circumstances to meet."<br/><b>William F. Halsey</b>',
    '"Man is only truly great when he acts from his passions."<br/><b>Benjamin Disreali</b>',
    '"The price of greatness is responsibility."<br/><b>Winston Churchill</b>',
    '"To achieve great things we must live as if we were never going to die."<br/><b>Marquis de Vauvenargues</b>'
    );
    i = 0;
    tickerIt();
}
 
function tickerIt(){
    if( i == tickerItems.length ){
        i = 0;
    }
    //change without effect
    //$('#ticker').html(tickerItems[i]);
 
    //change with effect
    $('#ticker').fadeOut("slow", function(){
        $(this).html(tickerItems[i]).fadeIn("slow");
        i++;
    });
 
    //repeat
    setTimeout(tickerIt, 5000);
}