JSFiddle - React, Tailwind, and code Playground
HTML
<div id="one" class="box"></div>
<div id="two" class="box"></div>
<div id="three" class="box"></div>
<div id="four" class="box"></div>
<div id="hover">HOVER ME</div>
CSS
.box {
height:100px;
width:100px;
display:inline-block;
opacity:0;
}
#one {
background:red;
}
#two {
background:blue;
}
#three {
background:green;
}
#four {
background:yellow;
}
JavaScript
$("#hover").on({
'mouseenter': function(e) {
// Animate the box set to visible
animateBoxSet(1);
},
'mouseleave': function(e) {
// Animate the box set to invisible
animateBoxSet(0);
}
});
function animateBoxSet(opacity) {
// For each box
$('.box').each(function (index, element) {
// Set the delay based on the index in the set
var delay = 250 * index;
// Animate it the visibility after the delay
$(element).stop(true).delay(delay).animate({
'opacity': opacity
});
});
}