seconds slide2

by lovromar

HTML

<div class="show">
<rec>First item</rec>
<rec>Second item</rec>
<rec>Third item</rec>
<rec>Fourth item</rec>
    <p class="show-line"></p>
</div>

JavaScript

var i = 0;
var items = [];

$('.show > rec').hide();

$('rec').each(function(index) {
    var x = $(this).text();
    items[items.length] = x;
});

function rotate() {

    setTimeout(function() {
        if (i > items.length) {
            i = 0;
        }
        $('p.show-line').html(items[i]).hide().fadeIn('slow');
        i++;
        rotate();
    }, 5000);
}

rotate();