Advertisement
nu11secur1ty

snowstorm.js

Dec 14th, 2017
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** @license
  2.  * DHTML Snowstorm! JavaScript-based snow for web pages
  3.  * Making it snow on the internets since 2003. You're welcome.
  4.  * -----------------------------------------------------------
  5.  * Version 1.44.20131125 (Previous rev: 1.44.20131111)
  6.  * Copyright (c) 2007, Scott Schiller. All rights reserved.
  7.  * Code provided under the BSD License
  8.  * http://schillmania.com/projects/snowstorm/license.txt
  9.  */
  10.  
  11. /*jslint nomen: true, plusplus: true, sloppy: true, vars: true, white: true */
  12. /*global window, document, navigator, clearInterval, setInterval */
  13.  
  14. var snowStorm = (function(window, document) {
  15.  
  16.   // --- common properties ---
  17.  
  18.   this.autoStart = true;          // Whether the snow should start automatically or not.
  19.   this.excludeMobile = true;      // Snow is likely to be bad news for mobile phones' CPUs (and batteries.) Enable at your own risk.
  20.   this.flakesMax = 128;           // Limit total amount of snow made (falling + sticking)
  21.   this.flakesMaxActive = 64;      // Limit amount of snow falling at once (less = lower CPU use)
  22.   this.animationInterval = 33;    // Theoretical "miliseconds per frame" measurement. 20 = fast + smooth, but high CPU use. 50 = more conservative, but slower
  23.   this.useGPU = true;             // Enable transform-based hardware acceleration, reduce CPU load.
  24.   this.flakeBottom = null;        // Integer for Y axis snow limit, 0 or null for "full-screen" snow effect
  25.   this.followMouse = true;        // Snow movement can respond to the user's mouse
  26.   this.snowColor = '#fff';        // Don't eat (or use?) yellow snow.
  27.   this.snowCharacter = '•';  // • = bullet, · is square on some systems etc.
  28.   this.snowStick = true;          // Whether or not snow should "stick" at the bottom. When off, will never collect.
  29.   this.targetElement = null;      // element which snow will be appended to (null = document.body) - can be an element ID eg. 'myDiv', or a DOM node reference
  30.   this.useMeltEffect = true;      // When recycling fallen snow (or rarely, when falling), have it "melt" and fade out if browser supports it
  31.   this.useTwinkleEffect = false;  // Allow snow to randomly "flicker" in and out of view while falling
  32.   this.usePositionFixed = false;  // true = snow does not shift vertically when scrolling. May increase CPU load, disabled by default - if enabled, used only where supported
  33.  
  34.   // --- less-used bits ---
  35.  
  36.   this.freezeOnBlur = true;       // Only snow when the window is in focus (foreground.) Saves CPU.
  37.   this.flakeLeftOffset = 0;       // Left margin/gutter space on edge of container (eg. browser window.) Bump up these values if seeing horizontal scrollbars.
  38.   this.flakeRightOffset = 0;      // Right margin/gutter space on edge of container
  39.   this.flakeWidth = 8;            // Max pixel width reserved for snow element
  40.   this.flakeHeight = 8;           // Max pixel height reserved for snow element
  41.   this.vMaxX = 5;                 // Maximum X velocity range for snow
  42.   this.vMaxY = 4;                 // Maximum Y velocity range for snow
  43.   this.zIndex = 0;                // CSS stacking order applied to each snowflake
  44.  
  45.   // --- "No user-serviceable parts inside" past this point, yadda yadda ---
  46.  
  47.   var storm = this,
  48.   features,
  49.   // UA sniffing and backCompat rendering mode checks for fixed position, etc.
  50.   isIE = navigator.userAgent.match(/msie/i),
  51.   isIE6 = navigator.userAgent.match(/msie 6/i),
  52.   isMobile = navigator.userAgent.match(/mobile|opera m(ob|in)/i),
  53.   isBackCompatIE = (isIE && document.compatMode === 'BackCompat'),
  54.   noFixed = (isBackCompatIE || isIE6),
  55.   screenX = null, screenX2 = null, screenY = null, scrollY = null, docHeight = null, vRndX = null, vRndY = null,
  56.   windOffset = 1,
  57.   windMultiplier = 2,
  58.   flakeTypes = 6,
  59.   fixedForEverything = false,
  60.   opacitySupported = (function(){
  61.     try {
  62.       document.createElement('div').style.opacity = '0.5';
  63.     } catch(e) {
  64.       return false;
  65.     }
  66.     return true;
  67.   }()),
  68.   didInit = false,
  69.   docFrag = document.createDocumentFragment();
  70.  
  71.   features = (function() {
  72.  
  73.     var getAnimationFrame;
  74.  
  75.     /**
  76.      * hat tip: paul irish
  77.      * http://paulirish.com/2011/requestanimationframe-for-smart-animating/
  78.      * https://gist.github.com/838785
  79.      */
  80.  
  81.     function timeoutShim(callback) {
  82.       window.setTimeout(callback, 1000/(storm.animationInterval || 20));
  83.     }
  84.  
  85.     var _animationFrame = (window.requestAnimationFrame ||
  86.         window.webkitRequestAnimationFrame ||
  87.         window.mozRequestAnimationFrame ||
  88.         window.oRequestAnimationFrame ||
  89.         window.msRequestAnimationFrame ||
  90.         timeoutShim);
  91.  
  92.     // apply to window, avoid "illegal invocation" errors in Chrome
  93.     getAnimationFrame = _animationFrame ? function() {
  94.       return _animationFrame.apply(window, arguments);
  95.     } : null;
  96.  
  97.     var testDiv;
  98.  
  99.     testDiv = document.createElement('div');
  100.  
  101.     function has(prop) {
  102.  
  103.       // test for feature support
  104.       var result = testDiv.style[prop];
  105.       return (result !== undefined ? prop : null);
  106.  
  107.     }
  108.  
  109.     // note local scope.
  110.     var localFeatures = {
  111.  
  112.       transform: {
  113.         ie:  has('-ms-transform'),
  114.         moz: has('MozTransform'),
  115.         opera: has('OTransform'),
  116.         webkit: has('webkitTransform'),
  117.         w3: has('transform'),
  118.         prop: null // the normalized property value
  119.       },
  120.  
  121.       getAnimationFrame: getAnimationFrame
  122.  
  123.     };
  124.  
  125.     localFeatures.transform.prop = (
  126.       localFeatures.transform.w3 ||
  127.       localFeatures.transform.moz ||
  128.       localFeatures.transform.webkit ||
  129.       localFeatures.transform.ie ||
  130.       localFeatures.transform.opera
  131.     );
  132.  
  133.     testDiv = null;
  134.  
  135.     return localFeatures;
  136.  
  137.   }());
  138.  
  139.   this.timer = null;
  140.   this.flakes = [];
  141.   this.disabled = false;
  142.   this.active = false;
  143.   this.meltFrameCount = 20;
  144.   this.meltFrames = [];
  145.  
  146.   this.setXY = (noFixed ? function(o, x, y) {
  147.  
  148.     // IE 6 and the like
  149.     if (o) {
  150.       o.style.right = (100-(x/screenX*100)) + '%';
  151.       // avoid creating vertical scrollbars
  152.       o.style.top = (Math.min(y, docHeight-storm.flakeHeight)) + 'px';
  153.     }
  154.  
  155.   } : function(o, x, y) {
  156.  
  157.     if (o) {
  158.  
  159.       if (!storm.flakeBottom) {
  160.  
  161.         // if not using a fixed bottom coordinate...
  162.         o.style.right = (100-(x/screenX*100)) + '%';
  163.         o.style.bottom = (100-(y/screenY*100)) + '%';
  164.  
  165.       } else {
  166.  
  167.         // absolute top.
  168.         o.style.right = (100-(x/screenX*100)) + '%';
  169.         o.style.top = (Math.min(y, docHeight-storm.flakeHeight)) + 'px';
  170.  
  171.       }
  172.  
  173.     }
  174.  
  175.   });
  176.  
  177.   this.events = (function() {
  178.  
  179.     var old = (!window.addEventListener && window.attachEvent), slice = Array.prototype.slice,
  180.     evt = {
  181.       add: (old?'attachEvent':'addEventListener'),
  182.       remove: (old?'detachEvent':'removeEventListener')
  183.     };
  184.  
  185.     function getArgs(oArgs) {
  186.       var args = slice.call(oArgs), len = args.length;
  187.       if (old) {
  188.         args[1] = 'on' + args[1]; // prefix
  189.         if (len > 3) {
  190.           args.pop(); // no capture
  191.         }
  192.       } else if (len === 3) {
  193.         args.push(false);
  194.       }
  195.       return args;
  196.     }
  197.  
  198.     function apply(args, sType) {
  199.       var element = args.shift(),
  200.           method = [evt[sType]];
  201.       if (old) {
  202.         element[method](args[0], args[1]);
  203.       } else {
  204.         element[method].apply(element, args);
  205.       }
  206.     }
  207.  
  208.     function addEvent() {
  209.       apply(getArgs(arguments), 'add');
  210.     }
  211.  
  212.     function removeEvent() {
  213.       apply(getArgs(arguments), 'remove');
  214.     }
  215.  
  216.     return {
  217.       add: addEvent,
  218.       remove: removeEvent
  219.     };
  220.  
  221.   }());
  222.  
  223.   function rnd(n,min) {
  224.     if (isNaN(min)) {
  225.       min = 0;
  226.     }
  227.     return (Math.random()*n)+min;
  228.   }
  229.  
  230.   function plusMinus(n) {
  231.     return (parseInt(rnd(2),10)===1?n*-1:n);
  232.   }
  233.  
  234.   this.randomizeWind = function() {
  235.     var i;
  236.     vRndX = plusMinus(rnd(storm.vMaxX,0.2));
  237.     vRndY = rnd(storm.vMaxY,0.2);
  238.     if (this.flakes) {
  239.       for (i=0; i<this.flakes.length; i++) {
  240.         if (this.flakes[i].active) {
  241.           this.flakes[i].setVelocities();
  242.         }
  243.       }
  244.     }
  245.   };
  246.  
  247.   this.scrollHandler = function() {
  248.     var i;
  249.     // "attach" snowflakes to bottom of window if no absolute bottom value was given
  250.     scrollY = (storm.flakeBottom ? 0 : parseInt(window.scrollY || document.documentElement.scrollTop || (noFixed ? document.body.scrollTop : 0), 10));
  251.     if (isNaN(scrollY)) {
  252.       scrollY = 0; // Netscape 6 scroll fix
  253.     }
  254.     if (!fixedForEverything && !storm.flakeBottom && storm.flakes) {
  255.       for (i=0; i<storm.flakes.length; i++) {
  256.         if (storm.flakes[i].active === 0) {
  257.           storm.flakes[i].stick();
  258.         }
  259.       }
  260.     }
  261.   };
  262.  
  263.   this.resizeHandler = function() {
  264.     if (window.innerWidth || window.innerHeight) {
  265.       screenX = window.innerWidth - 16 - storm.flakeRightOffset;
  266.       screenY = (storm.flakeBottom || window.innerHeight);
  267.     } else {
  268.       screenX = (document.documentElement.clientWidth || document.body.clientWidth || document.body.scrollWidth) - (!isIE ? 8 : 0) - storm.flakeRightOffset;
  269.       screenY = storm.flakeBottom || document.documentElement.clientHeight || document.body.clientHeight || document.body.scrollHeight;
  270.     }
  271.     docHeight = document.body.offsetHeight;
  272.     screenX2 = parseInt(screenX/2,10);
  273.   };
  274.  
  275.   this.resizeHandlerAlt = function() {
  276.     screenX = storm.targetElement.offsetLeft + storm.targetElement.offsetWidth - storm.flakeRightOffset;
  277.     screenY = storm.flakeBottom || (storm.targetElement.offsetTop + storm.targetElement.offsetHeight);
  278.     screenX2 = parseInt(screenX/2,10);
  279.     docHeight = document.body.offsetHeight;
  280.   };
  281.  
  282.   this.freeze = function() {
  283.     // pause animation
  284.     if (!storm.disabled) {
  285.       storm.disabled = 1;
  286.     } else {
  287.       return false;
  288.     }
  289.     storm.timer = null;
  290.   };
  291.  
  292.   this.resume = function() {
  293.     if (storm.disabled) {
  294.        storm.disabled = 0;
  295.     } else {
  296.       return false;
  297.     }
  298.     storm.timerInit();
  299.   };
  300.  
  301.   this.toggleSnow = function() {
  302.     if (!storm.flakes.length) {
  303.       // first run
  304.       storm.start();
  305.     } else {
  306.       storm.active = !storm.active;
  307.       if (storm.active) {
  308.         storm.show();
  309.         storm.resume();
  310.       } else {
  311.         storm.stop();
  312.         storm.freeze();
  313.       }
  314.     }
  315.   };
  316.  
  317.   this.stop = function() {
  318.     var i;
  319.     this.freeze();
  320.     for (i=0; i<this.flakes.length; i++) {
  321.       this.flakes[i].o.style.display = 'none';
  322.     }
  323.     storm.events.remove(window,'scroll',storm.scrollHandler);
  324.     storm.events.remove(window,'resize',storm.resizeHandler);
  325.     if (storm.freezeOnBlur) {
  326.       if (isIE) {
  327.         storm.events.remove(document,'focusout',storm.freeze);
  328.         storm.events.remove(document,'focusin',storm.resume);
  329.       } else {
  330.         storm.events.remove(window,'blur',storm.freeze);
  331.         storm.events.remove(window,'focus',storm.resume);
  332.       }
  333.     }
  334.   };
  335.  
  336.   this.show = function() {
  337.     var i;
  338.     for (i=0; i<this.flakes.length; i++) {
  339.       this.flakes[i].o.style.display = 'block';
  340.     }
  341.   };
  342.  
  343.   this.SnowFlake = function(type,x,y) {
  344.     var s = this;
  345.     this.type = type;
  346.     this.x = x||parseInt(rnd(screenX-20),10);
  347.     this.y = (!isNaN(y)?y:-rnd(screenY)-12);
  348.     this.vX = null;
  349.     this.vY = null;
  350.     this.vAmpTypes = [1,1.2,1.4,1.6,1.8]; // "amplification" for vX/vY (based on flake size/type)
  351.     this.vAmp = this.vAmpTypes[this.type] || 1;
  352.     this.melting = false;
  353.     this.meltFrameCount = storm.meltFrameCount;
  354.     this.meltFrames = storm.meltFrames;
  355.     this.meltFrame = 0;
  356.     this.twinkleFrame = 0;
  357.     this.active = 1;
  358.     this.fontSize = (10+(this.type/5)*10);
  359.     this.o = document.createElement('div');
  360.     this.o.innerHTML = storm.snowCharacter;
  361.     this.o.style.color = storm.snowColor;
  362.     this.o.style.position = (fixedForEverything?'fixed':'absolute');
  363.     if (storm.useGPU && features.transform.prop) {
  364.       // GPU-accelerated snow.
  365.       this.o.style[features.transform.prop] = 'translate3d(0px, 0px, 0px)';
  366.     }
  367.     this.o.style.width = storm.flakeWidth+'px';
  368.     this.o.style.height = storm.flakeHeight+'px';
  369.     this.o.style.fontFamily = 'arial,verdana';
  370.     this.o.style.cursor = 'default';
  371.     this.o.style.overflow = 'hidden';
  372.     this.o.style.fontWeight = 'normal';
  373.     this.o.style.zIndex = storm.zIndex;
  374.     docFrag.appendChild(this.o);
  375.  
  376.     this.refresh = function() {
  377.       if (isNaN(s.x) || isNaN(s.y)) {
  378.         // safety check
  379.         return false;
  380.       }
  381.       storm.setXY(s.o, s.x, s.y);
  382.     };
  383.  
  384.     this.stick = function() {
  385.       if (noFixed || (storm.targetElement !== document.documentElement && storm.targetElement !== document.body)) {
  386.         s.o.style.top = (screenY+scrollY-storm.flakeHeight)+'px';
  387.       } else if (storm.flakeBottom) {
  388.         s.o.style.top = storm.flakeBottom+'px';
  389.       } else {
  390.         s.o.style.display = 'none';
  391.         s.o.style.bottom = '0%';
  392.         s.o.style.position = 'fixed';
  393.         s.o.style.display = 'block';
  394.       }
  395.     };
  396.  
  397.     this.vCheck = function() {
  398.       if (s.vX>=0 && s.vX<0.2) {
  399.         s.vX = 0.2;
  400.       } else if (s.vX<0 && s.vX>-0.2) {
  401.         s.vX = -0.2;
  402.       }
  403.       if (s.vY>=0 && s.vY<0.2) {
  404.         s.vY = 0.2;
  405.       }
  406.     };
  407.  
  408.     this.move = function() {
  409.       var vX = s.vX*windOffset, yDiff;
  410.       s.x += vX;
  411.       s.y += (s.vY*s.vAmp);
  412.       if (s.x >= screenX || screenX-s.x < storm.flakeWidth) { // X-axis scroll check
  413.         s.x = 0;
  414.       } else if (vX < 0 && s.x-storm.flakeLeftOffset < -storm.flakeWidth) {
  415.         s.x = screenX-storm.flakeWidth-1; // flakeWidth;
  416.       }
  417.       s.refresh();
  418.       yDiff = screenY+scrollY-s.y+storm.flakeHeight;
  419.       if (yDiff<storm.flakeHeight) {
  420.         s.active = 0;
  421.         if (storm.snowStick) {
  422.           s.stick();
  423.         } else {
  424.           s.recycle();
  425.         }
  426.       } else {
  427.         if (storm.useMeltEffect && s.active && s.type < 3 && !s.melting && Math.random()>0.998) {
  428.           // ~1/1000 chance of melting mid-air, with each frame
  429.           s.melting = true;
  430.           s.melt();
  431.           // only incrementally melt one frame
  432.           // s.melting = false;
  433.         }
  434.         if (storm.useTwinkleEffect) {
  435.           if (s.twinkleFrame < 0) {
  436.             if (Math.random() > 0.97) {
  437.               s.twinkleFrame = parseInt(Math.random() * 8, 10);
  438.             }
  439.           } else {
  440.             s.twinkleFrame--;
  441.             if (!opacitySupported) {
  442.               s.o.style.visibility = (s.twinkleFrame && s.twinkleFrame % 2 === 0 ? 'hidden' : 'visible');
  443.             } else {
  444.               s.o.style.opacity = (s.twinkleFrame && s.twinkleFrame % 2 === 0 ? 0 : 1);
  445.             }
  446.           }
  447.         }
  448.       }
  449.     };
  450.  
  451.     this.animate = function() {
  452.       // main animation loop
  453.       // move, check status, die etc.
  454.       s.move();
  455.     };
  456.  
  457.     this.setVelocities = function() {
  458.       s.vX = vRndX+rnd(storm.vMaxX*0.12,0.1);
  459.       s.vY = vRndY+rnd(storm.vMaxY*0.12,0.1);
  460.     };
  461.  
  462.     this.setOpacity = function(o,opacity) {
  463.       if (!opacitySupported) {
  464.         return false;
  465.       }
  466.       o.style.opacity = opacity;
  467.     };
  468.  
  469.     this.melt = function() {
  470.       if (!storm.useMeltEffect || !s.melting) {
  471.         s.recycle();
  472.       } else {
  473.         if (s.meltFrame < s.meltFrameCount) {
  474.           s.setOpacity(s.o,s.meltFrames[s.meltFrame]);
  475.           s.o.style.fontSize = s.fontSize-(s.fontSize*(s.meltFrame/s.meltFrameCount))+'px';
  476.           s.o.style.lineHeight = storm.flakeHeight+2+(storm.flakeHeight*0.75*(s.meltFrame/s.meltFrameCount))+'px';
  477.           s.meltFrame++;
  478.         } else {
  479.           s.recycle();
  480.         }
  481.       }
  482.     };
  483.  
  484.     this.recycle = function() {
  485.       s.o.style.display = 'none';
  486.       s.o.style.position = (fixedForEverything?'fixed':'absolute');
  487.       s.o.style.bottom = 'auto';
  488.       s.setVelocities();
  489.       s.vCheck();
  490.       s.meltFrame = 0;
  491.       s.melting = false;
  492.       s.setOpacity(s.o,1);
  493.       s.o.style.padding = '0px';
  494.       s.o.style.margin = '0px';
  495.       s.o.style.fontSize = s.fontSize+'px';
  496.       s.o.style.lineHeight = (storm.flakeHeight+2)+'px';
  497.       s.o.style.textAlign = 'center';
  498.       s.o.style.verticalAlign = 'baseline';
  499.       s.x = parseInt(rnd(screenX-storm.flakeWidth-20),10);
  500.       s.y = parseInt(rnd(screenY)*-1,10)-storm.flakeHeight;
  501.       s.refresh();
  502.       s.o.style.display = 'block';
  503.       s.active = 1;
  504.     };
  505.  
  506.     this.recycle(); // set up x/y coords etc.
  507.     this.refresh();
  508.  
  509.   };
  510.  
  511.   this.snow = function() {
  512.     var active = 0, flake = null, i, j;
  513.     for (i=0, j=storm.flakes.length; i<j; i++) {
  514.       if (storm.flakes[i].active === 1) {
  515.         storm.flakes[i].move();
  516.         active++;
  517.       }
  518.       if (storm.flakes[i].melting) {
  519.         storm.flakes[i].melt();
  520.       }
  521.     }
  522.     if (active<storm.flakesMaxActive) {
  523.       flake = storm.flakes[parseInt(rnd(storm.flakes.length),10)];
  524.       if (flake.active === 0) {
  525.         flake.melting = true;
  526.       }
  527.     }
  528.     if (storm.timer) {
  529.       features.getAnimationFrame(storm.snow);
  530.     }
  531.   };
  532.  
  533.   this.mouseMove = function(e) {
  534.     if (!storm.followMouse) {
  535.       return true;
  536.     }
  537.     var x = parseInt(e.clientX,10);
  538.     if (x<screenX2) {
  539.       windOffset = -windMultiplier+(x/screenX2*windMultiplier);
  540.     } else {
  541.       x -= screenX2;
  542.       windOffset = (x/screenX2)*windMultiplier;
  543.     }
  544.   };
  545.  
  546.   this.createSnow = function(limit,allowInactive) {
  547.     var i;
  548.     for (i=0; i<limit; i++) {
  549.       storm.flakes[storm.flakes.length] = new storm.SnowFlake(parseInt(rnd(flakeTypes),10));
  550.       if (allowInactive || i>storm.flakesMaxActive) {
  551.         storm.flakes[storm.flakes.length-1].active = -1;
  552.       }
  553.     }
  554.     storm.targetElement.appendChild(docFrag);
  555.   };
  556.  
  557.   this.timerInit = function() {
  558.     storm.timer = true;
  559.     storm.snow();
  560.   };
  561.  
  562.   this.init = function() {
  563.     var i;
  564.     for (i=0; i<storm.meltFrameCount; i++) {
  565.       storm.meltFrames.push(1-(i/storm.meltFrameCount));
  566.     }
  567.     storm.randomizeWind();
  568.     storm.createSnow(storm.flakesMax); // create initial batch
  569.     storm.events.add(window,'resize',storm.resizeHandler);
  570.     storm.events.add(window,'scroll',storm.scrollHandler);
  571.     if (storm.freezeOnBlur) {
  572.       if (isIE) {
  573.         storm.events.add(document,'focusout',storm.freeze);
  574.         storm.events.add(document,'focusin',storm.resume);
  575.       } else {
  576.         storm.events.add(window,'blur',storm.freeze);
  577.         storm.events.add(window,'focus',storm.resume);
  578.       }
  579.     }
  580.     storm.resizeHandler();
  581.     storm.scrollHandler();
  582.     if (storm.followMouse) {
  583.       storm.events.add(isIE?document:window,'mousemove',storm.mouseMove);
  584.     }
  585.     storm.animationInterval = Math.max(20,storm.animationInterval);
  586.     storm.timerInit();
  587.   };
  588.  
  589.   this.start = function(bFromOnLoad) {
  590.     if (!didInit) {
  591.       didInit = true;
  592.     } else if (bFromOnLoad) {
  593.       // already loaded and running
  594.       return true;
  595.     }
  596.     if (typeof storm.targetElement === 'string') {
  597.       var targetID = storm.targetElement;
  598.       storm.targetElement = document.getElementById(targetID);
  599.       if (!storm.targetElement) {
  600.         throw new Error('Snowstorm: Unable to get targetElement "'+targetID+'"');
  601.       }
  602.     }
  603.     if (!storm.targetElement) {
  604.       storm.targetElement = (document.docuentElement || document.body);
  605.     }
  606.     if (storm.targetElement !== document.documentElement && storm.targetElement !== document.body) {
  607.       storm.resizeHandler = storm.resizeHandlerAlt; // re-map handler to get element instead of screen dimensions
  608.     }
  609.     storm.resizeHandler(); // get bounding box elements
  610.     storm.usePositionFixed = (storm.usePositionFixed && !noFixed && !storm.flakeBottom); // whether or not position:fixed is to be used
  611.     fixedForEverything = storm.usePositionFixed;
  612.     if (screenX && screenY && !storm.disabled) {
  613.       storm.init();
  614.       storm.active = true;
  615.     }
  616.   };
  617.  
  618.   function doDelayedStart() {
  619.     window.setTimeout(function() {
  620.       storm.start(true);
  621.     }, 20);
  622.     // event cleanup
  623.     storm.events.remove(isIE?document:window,'mousemove',doDelayedStart);
  624.   }
  625.  
  626.   function doStart() {
  627.     if (!storm.excludeMobile || !isMobile) {
  628.       doDelayedStart();
  629.     }
  630.     // event cleanup
  631.     storm.events.remove(window, 'load', doStart);
  632.   }
  633.  
  634.   // hooks for starting the snow
  635.   if (storm.autoStart) {
  636.     storm.events.add(window, 'load', doStart, false);
  637.   }
  638.  
  639.   return this;
  640.  
  641. }(window, document));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement