首页 » 归档, 捣鼓折腾 » (*^ ^*)(^ *) 博客里下起了雪

(*^ ^*)(^ *) 博客里下起了雪

时间:2012-12-18作者:三秒掉线君分类:归档, 捣鼓折腾评论:2

分享: 腾讯微博 新浪微博

今天杭州天气很冷,早上绝对不想起床啊,但是不得不起,没下雪,天气预报说零下了,原先是说雨夹雪的=L=
看见微博上很多北京,天津的人们欢实的晒雪人的照片啊!
于是不如应景的,博客里也搞一下下雪的效果吧!

原先因为《WordPress卖萌:求包养》这篇文章,
在footer里增加了

  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>

于是这次只要在上面那串代码下面,footer的body前面增加以下的代码就可以了
(createSnow(“”, 40) 是改变雪花密度,this.size = Math.random() * 5 + 5 是雪片大小)

  1. <script type="text/javascript" language="javascript">
  2. (function() {
  3. function k(a, b, c) {
  4. if (a.addEventListener) a.addEventListener(b, c, false);
  5. else a.attachEvent && a.attachEvent("on" + b, c)
  6. }
  7. function g(a) {
  8. if (typeof window.onload != "function") window.onload = a;
  9. else {
  10. var b = window.onload;
  11. window.onload = function() {
  12. b();
  13. a()
  14. }
  15. }
  16. }
  17. function h() {
  18. var a = {};
  19. for (type in {
  20. Top: "",
  21. Left: ""
  22. }) {
  23. var b = type == "Top" ? "Y": "X";
  24. if (typeof window["page" + b + "Offset"] != "undefined")
  25. a[type.toLowerCase()] = window["page" + b + "Offset"];
  26. else {
  27. b = document.documentElement.clientHeight ? document.documentElement: document.body;
  28. a[type.toLowerCase()] = b["scroll" + type]
  29. }
  30. }
  31. return a
  32. }
  33. function l() {
  34. var a = document.body,
  35. b;
  36. if (window.innerHeight) b = window.innerHeight;
  37. else if (a.parentElement.clientHeight) b = a.parentElement.clientHeight;
  38. else if (a && a.clientHeight) b = a.clientHeight;
  39. return b
  40. }
  41. function i(a) {
  42. this.parent = document.body;
  43. this.createEl(this.parent, a);
  44. this.size = Math.random() * 5 + 5;
  45. this.el.style.width = Math.round(this.size) + "px";
  46. this.el.style.height = Math.round(this.size) + "px";
  47. this.maxLeft = document.body.offsetWidth - this.size;
  48. this.maxTop = document.body.offsetHeight - this.size;
  49. this.left = Math.random() * this.maxLeft;
  50. this.top = h().top + 1;
  51. this.angle = 1.4 + 0.2 * Math.random();
  52. this.minAngle = 1.4;
  53. this.maxAngle = 1.6;
  54. this.angleDelta = 0.01 * Math.random();
  55. this.speed = 2 + Math.random()
  56. }
  57. var j = false;
  58. g(function() {
  59. j = true
  60. });
  61. var f = true;
  62. window.createSnow = function(a, b) {
  63. if (j) {
  64. var c = [],
  65. m = setInterval(function() {
  66. f && b > c.length && Math.random()
  67. < b * 0.0025 && c.push(new i(a)); ! f && !c.length && clearInterval(m);
  68. for (var e = h().top, n = l(), d = c.length - 1; d >= 0; d--)
  69. if (c[d]) if (c[d].top < e || c[d].top + c[d].size + 1 > e + n) {
  70. c[d].remove();
  71. c[d] = null;
  72. c.splice(d, 1)
  73. } else {
  74. c[d].move();
  75. c[d].draw()
  76. }
  77. },
  78. 40);
  79. k(window, "scroll",
  80. function() {
  81. for (var e = c.length - 1; e >= 0; e--) c[e].draw()
  82. })
  83. } else g(function() {
  84. createSnow(a, b)
  85. })
  86. };
  87. window.removeSnow = function() {
  88. f = false
  89. };
  90. i.prototype = {
  91. createEl: function(a, b) {
  92. this.el = document.createElement("img");
  93. this.el.setAttribute
  94. ("src", b + "下雪的图片的地址,也可以下下团子,下下银子什么的,噗");
  95. this.el.style.position = "absolute";
  96. this.el.style.display = "block";
  97. this.el.style.zIndex = "99999";
  98. this.parent.appendChild(this.el)
  99. },
  100. move: function() {
  101. if (this.angle < this.minAngle || this.angle > this.maxAngle)
  102. this.angleDelta = -this.angleDelta;
  103. this.angle += this.angleDelta;
  104. this.left += this.speed * Math.cos(this.angle * Math.PI);
  105. this.top -= this.speed * Math.sin(this.angle * Math.PI);
  106. if (this.left < 0) this.left = this.maxLeft;
  107. else if (this.left > this.maxLeft) this.left = 0
  108. },
  109. draw: function() {
  110. this.el.style.top = Math.round(this.top) + "px";
  111. this.el.style.left = Math.round(this.left) + "px"
  112. },
  113. remove: function() {
  114. this.parent.removeChild(this.el);
  115. this.parent = this.el = null
  116. }
  117. }
  118. })();
  119. createSnow("", 40);
  120. </script>



无觅相关文章插件,快速提升流量

» 版权所有:明夜微凉 » 《(*^ ^*)(^ *) 博客里下起了雪》
» 本文链接:http://hzhgd.net/blog/dflmywl/index.php/archives/808
» 关于站长:BO主是一朵反射弧长、有拖延症、爱吐槽影视剧、偶尔剪个MV的死宅,有事请留言(つω`)~


    • 今天的天气预报说本周六会有一股强冷空气南下,杭州会有雨夹雪,还算是比较大的,我想南京应该也会持续降温吧,说不定也会雨夹雪来一场呢!不过南方从来湿冷,雨夹雪跟不下雪也差不多( ̄_ ̄|||)

返回顶部