JSFiddle - React, Tailwind, and code Playground
HTML
<!-- Here we have an element that has an overlay that appears on mouseover. -->
<div class="with-overlay">
<div class="overlay">
<p>It's an overlay!</p>
</div>
</div>
CSS
.with-overlay {
position: relative;
/* These are here just to make an anchor for the overlay */
height: 300px;
width: 300px;
background: #000;
}
.with-overlay:hover .overlay {
/* This line breaks the animation.
* Remove it, and the animation works every time. */
display: block;
}
/* ...and matching div overlay */
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-origin: content-box;
z-index: 150;
display: none;
}
.overlay p {
/* display: none;*/
padding: 25px;
background: rgba(255, 230, 230, 0.8);
}
JavaScript
/* I've tried with slideDown/Up and fadeIn/Out,
* but I suspect that any animation here would
* suffer the same issue. */
$('.with-overlay').hover(
function() {
$('.overlay', this).stop(true, true).slideDown();
},
function() {
$('.overlay', this).stop(true, true).slideUp();
}
);