JSFiddle - React, Tailwind, and code Playground
HTML
<span style="display:none;" id="test1"></span><br />
<span style="display:none;" id="test2"></span><br />
<span style="display:none;" id="test3"></span><br />
JavaScript
function rotate(sID,aWords,iIndex,bShuffle){
if (bShuffle==true) {
for(var j, x, i = aWords.length; i; j = Math.floor(Math.random() * i), x = aWords[--i], aWords[i] = aWords[j], aWords[j] = x);
}
$("#"+sID).html(aWords[iIndex]).fadeIn(1000, function() {
iIndex==(aWords.length-1)? iIndex=0:iIndex++;
$("#"+sID).fadeOut(1000, function() {
rotate(sID,aWords,iIndex);
});
});
}
var iCount1=0;
var iCount2=0;
rotate("test1",["Hello", "World", "Foo"], iCount1, false);
rotate("test3",["John", "Bob", "Billy", "Mike", "Larry"], iCount2, true);