JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<div class="container">
<div id="1" class="red square">1</div>
<div id="2" class="yellow square">2</div>
<div id="3" class="blue square">3</div>
<div id="4" class="green square">4</div>
</div>
CSS
.square {
width: 200px;
height: 50px;
opacity: 0.2;
display: inline;
}
JavaScript
var arr = [1, 4, 2, 3];
var arr2 = [2, 3, 2, 3];
var arr3 = [4, 3, 2, 3];
var arrays = [arr, arr2, arr3];
var a = arrays.slice(0);
function animate(elem) {
var el = elem.shift();
if (el) {
return $("#" + el).animate({
opacity: 1
}, 500, function() {
return $(this).animate({
opacity: 0.2
}, 1000)
}).promise().then(animate.bind(null, elem))
}
}; //Need to iterate through `arrays` if possible.
(function cycle() {
return animate(a.shift())
.then(a.length && cycle || alert.bind(null, "complete"))
}())
//The idea is that I run through the array, get some user input, run through the second, get user input, etc.