JS function for animation without CSS. Code example open

JS function for animation without CSS. Code example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
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); 
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation