JSFiddle - React, Tailwind, and code Playground
by norcaljohnny
HTML
<div id="page_title"></div>
<span id="text-reload">Reload</span>
JavaScript
// custom jquery plugin loadText()
$.fn.loadText = function( textArray, interval ) {
return this.each( function() {
var obj = $(this);
obj.fadeOut( 'slow', function() {
var elem = textArray[0];
obj.empty().html( elem );
textArray.shift();
textArray.push(elem);
obj.fadeIn( 'fast' );
});
timeOut = setTimeout( function(){ obj.loadText( textArray, interval )}, interval );
$("#text-reload").click( function(){
if( !obj.is(':animated') ) { clearTimeout( timeOut ); obj.loadText( textArray, interval );} // animation check prevents "too much recursion" error in jQuery
});
});
};
$(document).ready(function() {
var helloArray = ["Hi I am a title", "Hi I am another title", "I am also a title", "more", "and more", "and even more", "aloha", "see ya!"];
$('#page_title').loadText( helloArray, 5000 ); // ( array, interval )
document.title = $('#page_title').text();
});