JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img id="img" src="https://www.industrialempathy.com/img/remote/ZiClJf-1920w.jpg" width="200px" height="150px">
<script src="script.js"></script>
</body>
</html>
JavaScript
function hideSlowly(element, width, height){
let el = document.querySelector(element);
el_opacity = 1;
el_h = parseInt(height);
el_w = parseInt(width);
let s = setInterval(function(){
el.style.opacity = el_opacity;
el_opacity -= 0.2;
el.style.height = el_h + "px";
el_h -= 2;
el.style.width = el_w + "px";
el_w -= 2;
}, 100)
if(el_opacity <= 0){
el.style.display = "none";
// hide the element
// opacity is 0 and element is hidden so clear interval
clearInterval(s)
}
}
hideSlowly("#img", "100", "100");