JSFiddle - React, Tailwind, and code Playground
HTML
<button id="fast">Fast</button>
<button id="normal">Normal</button>
<button id="slow">Slow</button>
<div id="fadey1" class="fadey"></div>
<div id="fadey2" class="fadey"></div>
CSS
.fadey {
position: absolute;
height: 50px;
width: 50px;
}
#fadey1 {
background: blue;
}
#fadey2 {
background: red;
}
JavaScript
$(document).ready(function () {
var faderIndex = 0,
faderOutSpeed = 2000,
faderInSpeed = 3000,
faders = $('.fadey');
$('button#fast').click(function () {
faderOutSpeed = 200;
faderInSpeed = 300;
});
$('button#normal').click(function () {
faderOutSpeed = 600;
faderInSpeed = 900;
});
$('button#slow').click(function () {
faderOutSpeed = 2000;
faderInSpeed = 3000;
});
function nextFade() {
$(faders[faderIndex]).fadeOut(faderInSpeed, function () {
faderIndex++;
if (faderIndex >= faders.length) faderIndex = 0;
$(faders[faderIndex]).fadeIn(faderOutSpeed, nextFade);
});
}
nextFade();
});