一連のアニメーションを実行して、最後に戻ることができます
/**
* Method to animate the news feed
*/
function scrollNews() {
// If latest news is not being hovered upon
if (!$('.latestnews').hasClass('hover')) {
// Get the currently visible update
var currentUpdate = $('.theupdates').find('p').filter(':visible').first();
// Get the next update
var nextUpdate = currentUpdate.next();
// If there are no next updates
if (nextUpdate.length === 0) {
// Get the first update and set it as the next update
nextUpdate = $('.theupdates').find('p').filter(':first-of-type');
}
// Animate the current update out
currentUpdate.hide('slow', function () {
// Animate the next update in
nextUpdate.show('slow', function () {
// Delay a little bit and then recursively call this method
window.setTimeout(scrollNews, 2000);
});
});
} else {
// Delay a little bit and then recursively call this method
window.setTimeout(scrollNews, 2000);
}
}
// Handle hover over news
$('.latestnews').on({
'mouseover': function (e) {
$(this).addClass('hover');
},
'mouseout': function (e) {
$(this).removeClass('hover');
}
});
// Start animation
scrollNews();
jsfiddle