JSFiddle - React, Tailwind, and code Playground
by Brett Gaynor
HTML
<section class="steps">class name of this section changes (see inspector)</section>
<div id="div1"></div> <!-- this could be removed -->
<button>Stop it Now.</button>
CSS
body{text-align:center;}
#div1{padding:20px;margin-top:0; text-align:center;}
JavaScript
$(document).ready(function() {
var items = ["one", "two", "three"],
$text = $( 'section.steps' ),
delay = 2; //seconds
function loop ( delay ) {
$.each( items, function ( i, elm ){
$text.delay( delay*1E3);
$text.queue(function(){
$text.html( items[i] );
$text.dequeue(); // e.g. this is not needed
$text.attr('class', 'step');
$text.addClass( items[i]);
});
$text.queue(function(){
if ( i == items.length -1 ) {
loop(delay);
}
$text.dequeue();
});
});
}
loop( delay );
$("button").on("click", function() {
$text.stop(true, false);
})
});