function fadeIn(element, time) { let opacity = 0; const interval = 16; const duration = time; function animate() { opacity += interval / duration; if (opacity >= 1) { opacity = 1; clearInterval(fadeInterval); } element.style.opacity = opacity; } const fadeInterval = setInterval(animate, interval); }
Add function to your element:
fadeIn(element, 1000);