[JavaScript] javascript 下雪效果 特效 →→→→→进入此内容的聊天室

来自 , 2019-08-15, 写在 JavaScript, 查看 101 次.
URL http://www.code666.cn/view/e8e0dd18
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. (function() {
  5.         function j(a, b, c) {
  6.                 if (a.addEventListener) a.addEventListener(b, c, false);
  7.                 else a.attachEvent && a.attachEvent("on" + b, c)
  8.         }
  9.         function f(a) {
  10.                 if (typeof window.onload != "function") window.onload = a;
  11.                 else {
  12.                         var b = window.onload;
  13.                         window.onload = function() {
  14.                                 b();
  15.                                 a()
  16.                         }
  17.                 }
  18.         }
  19.         function g() {
  20.                 var a = {};
  21.                 for (type in {
  22.                         Top: "",
  23.                         Left: ""
  24.                 }) {
  25.                         var b = type == "Top" ? "Y": "X";
  26.                         if (typeof window["page" + b + "Offset"] != "undefined") a[type.toLowerCase()] = window["page" + b + "Offset"];
  27.                         else {
  28.                                 b = document.documentElement.clientHeight ? document.documentElement: document.body;
  29.                                 a[type.toLowerCase()] = b["scroll" + type]
  30.                         }
  31.                 }
  32.                 return a
  33.         }
  34.         function k() {
  35.                 var a = document.body,
  36.                 b;
  37.                 if (window.innerHeight) b = window.innerHeight;
  38.                 else if (a.parentElement.clientHeight) b = a.parentElement.clientHeight;
  39.                 else if (a && a.clientHeight) b = a.clientHeight;
  40.                 return b
  41.         }
  42.         function h(a) {
  43.                 this.parent = document.body;
  44.                 this.createEl(this.parent, a);
  45.                 this.size = Math.random() * 5 + 5;
  46.                 this.el.style.width = Math.round(this.size) + "px";
  47.                 this.el.style.height = Math.round(this.size) + "px";
  48.                 this.maxLeft = document.body.offsetWidth - this.size;
  49.                 this.maxTop = document.body.offsetHeight - this.size;
  50.                 this.left = Math.random() * this.maxLeft;
  51.                 this.top = g().top + 1;
  52.                 this.angle = 1.4 + 0.2 * Math.random();
  53.                 this.minAngle = 1.4;
  54.                 this.maxAngle = 1.6;
  55.                 this.angleDelta = 0.01 * Math.random();
  56.                 this.speed = 2 + Math.random()
  57.         }
  58.         var i = false;
  59.         f(function() {
  60.                 i = true
  61.         });
  62.         window.createSnow = function(a, b) {
  63.                 if (i) {
  64.                         var c = [];
  65.                         setInterval(function() {
  66.                                 b > c.length && Math.random() < b * 0.0025 && c.push(new h(a));
  67.                                 for (var e = g().top, l = k(), d = c.length - 1; d >= 0; d--) if (c[d]) if (c[d].top < e || c[d].top > e + l) {
  68.                                         c[d].remove();
  69.                                         c.splice(d, 1)
  70.                                 } else {
  71.                                         c[d].move();
  72.                                         c[d].draw()
  73.                                 }
  74.                         },
  75.                         40);
  76.                         j(window, "scroll",
  77.                         function() {
  78.                                 for (var e = c.length - 1; e >= 0; e--) c[e].draw()
  79.                         })
  80.                 } else f(function() {
  81.                         createSnow(a, b)
  82.                 })
  83.         };
  84.         h.prototype = {
  85.                 createEl: function(a, b) {
  86.                         this.el = document.createElement("img");
  87.                         this.el.setAttribute("src", b + "snow" + Math.floor(Math.random() * 4) + ".gif");
  88.                         this.el.style.position = "absolute";
  89.                         this.el.style.display = "block";
  90.                         this.el.style.zIndex = "99999";
  91.                         this.parent.appendChild(this.el)
  92.                 },
  93.                 move: function() {
  94.                         if (this.angle < this.minAngle || this.angle > this.maxAngle) this.angleDelta = -this.angleDelta;
  95.                         this.angle += this.angleDelta;
  96.                         this.left += this.speed * Math.cos(this.angle * Math.PI);
  97.                         this.top -= this.speed * Math.sin(this.angle * Math.PI);
  98.                         if (this.top < 0) this.top = this.maxTop;
  99.                         else if (this.top > this.maxTop) this.top = 0;
  100.                         if (this.left < 0) this.left = this.maxLeft;
  101.                         else if (this.left > this.maxLeft) this.left = 0
  102.                 },
  103.                 draw: function() {
  104.                         this.el.style.top = Math.round(this.top) + "px";
  105.                         this.el.style.left = Math.round(this.left) + "px"
  106.                 },
  107.                 remove: function() {
  108.                         this.parent.removeChild(this.el)
  109.                 }
  110.         }
  111. })();
  112. </script>
  113. </head>
  114.  
  115. <body bgcolor="#999999">
  116. <script>
  117. //使用方法
  118. createSnow('...........', 60);//修改为自己的雪花图片存放目录,文件形式为snow1.gif  snow2.gif ......
  119. </script>
  120. </body>
  121. </html>
  122.  

回复 "javascript 下雪效果 特效"

这儿你可以回复上面这条便签

captcha