Having trouble with a simple animation using jQuery? While it may work smoothly in Firefox, you might be experiencing flickering in Chrome and Edge. Check out this jsfiddle for reference:
HTML
<div id="boxes-wrapper">
<div class="box"></div><div class="box"></div><div class="box"></div>
</div>
CSS
.box {
width: 150px;
height: 150px;
display: inline-block;
margin: 0;
padding: 0;
vertical-align: top;
}
.box:first-child {
background: pink;
}
.box:nth-child(2) {
background: skyblue;
}
.box:nth-child(3) {
background: gold;
}
.box.hover {
position: relative;
z-index: 20;
}
html, body {
position: relative;
width: 100%;
height: 100%;
}
#shadow {
display: none;
position: absolute;
left: 0;
top: 0;
background: black;
opacity: 0.7;
z-index: 10;
width: 100%;
height: 100%;
}
JavaScript
$('.box').hover(function() {
$(this).addClass('hover');
$('#shadow').show();
}, function() {
$(this).removeClass('hover');
$('#shadow').hide();
});
If you've been scouring Stack Overflow for solutions to eliminate this flicker issue without success, you're not alone.