JSFiddle - React, Tailwind, and code Playground
HTML
<div class="test"></div>
CSS
.test {
width: 200px;
height: 200px;
margin-top: 50px;
margin-bottom: 100px;
background-color: yellow;
opacity: 1;
}
JavaScript
var div = document.querySelector('.test');
function show(elem, t) {
elem.style.display = "block";
elem.style.opacity = 0;
var fadeEffect = setInterval(function () {
if (elem.style.opacity > 1) {
clearInterval(fadeEffect);
}
elem.style.opacity += 0.02; //0.02
}, t)
}
div.onclick = function () {
show(this, 19);
}