JSFiddle - React, Tailwind, and code Playground
HTML
<div id="fades">
<div>Hello #1</div>
<div>Hello #2</div>
<div>Hello #3</div>
<div>Hello #4</div>
<div>Hello #5</div>
<div>Hello #6</div>
<div>Hello #7</div>
<div>Hello #8</div>
<div>Hello #9</div>
<div>Hello #10</div>
</div>
JavaScript
// First hide them all
$("#fades div").hide();
function fades($div, cb) {
$div.fadeIn(1000, function () {
$div.fadeOut(1000, function () {
var $next = $div.next();
if ($next.length > 0) {
fades($next, cb);
}
else {
// The last element has faded away, call the callback
cb();
}
});
});
}
function startFading($firstDiv) {
fades($firstDiv, function () {
startFading($firstDiv);
});
}
startFading($("#fades div:first-child"));