MediaWiki:Gadget-snowfall.js

Страница интерфейса MediaWiki

(function () {

 var snowflakes = [];
 var numSnowflakes = 50;
 function createSnowflake() {
   var snowflake = document.createElement('div');
   snowflake.className = 'snowflake';
   snowflake.innerHTML = '❄';
   snowflake.style.left = Math.random() * 100 + 'vw';
   snowflake.style.animationDuration = 5 + Math.random() * 5 + 's';
   snowflake.style.fontSize = Math.random() * 10 + 10 + 'px';
   document.body.appendChild(snowflake);
   snowflakes.push(snowflake);
   setTimeout(function () {
     snowflake.remove();
     snowflakes.splice(snowflakes.indexOf(snowflake), 1);
   }, 10000);
 }
 function startSnowfall() {
   setInterval(createSnowflake, 300);
 }
 if (document.readyState === 'loading') {
   document.addEventListener('DOMContentLoaded', startSnowfall);
 } else {
   startSnowfall();
 }

})();