User:AlexTech01/snowflake.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Loading the CSS for snowflakes
importStylesheet("User:AlexTech01/snowflake.css");
console.log("%c[Snowflake]%c The `snowflake` user script has been loaded successfully. Enjoy the snowflakes!", "color: aqua", "");

function createSnowflake() {
	const snowflake = document.createElement('div');
	snowflake.classList.add('snowflake');
	snowflake.textContent = '❄';
	
	snowflake.style.left = Math.random() * 100 + 'vw';
	snowflake.style.opacity = Math.random();
	snowflake.style.fontSize = Math.random() * 20 + 10 + 'px';
	snowflake.style.animationDuration = Math.random() * 3 + 2 + 's';
	
	document.body.appendChild(snowflake);
	
	// Remove snowflake after it falls
	setTimeout(() => {
		snowflake.remove();
	}, 10000);
}

setInterval(createSnowflake, 100);