为wordpress添加下雪效果

<

p>大家是否注意到小站已经开始下雪啦?在西安期待好久的雪还是没有下下来,实在是按耐不住为小站添加了下雪效果,wordpress要实现的话很简单的哦,只要将下面的代码复制到主题模板里面的footer.php里面就ok啦.

&amp;amp;amp;lt;script type=&amp;amp;amp;quot;text/javascript&amp;amp;amp;quot; language=&amp;amp;amp;quot;javascript&amp;amp;amp;quot;&amp;amp;amp;gt;
(function() {
    function k(a, b, c) {
        if (a.addEventListener) a.addEventListener(b, c, false);
        else a.attachEvent &amp;amp;amp;amp;&amp;amp;amp;amp; a.attachEvent(&amp;amp;amp;quot;on&amp;amp;amp;quot; + b, c)
    }
    function g(a) {
        if (typeof window.onload != &amp;amp;amp;quot;function&amp;amp;amp;quot;) window.onload = a;
        else {
            var b = window.onload;
            window.onload = function() {
                b();
                a()
            }
        }
    }
    function h() {
        var a = {};
        for (type in {
            Top: &amp;amp;amp;quot;&amp;amp;amp;quot;,
            Left: &amp;amp;amp;quot;&amp;amp;amp;quot;
        }) {
            var b = type == &amp;amp;amp;quot;Top&amp;amp;amp;quot; ? &amp;amp;amp;quot;Y&amp;amp;amp;quot;: &amp;amp;amp;quot;X&amp;amp;amp;quot;;
            if (typeof window[&amp;amp;amp;quot;page&amp;amp;amp;quot; + b + &amp;amp;amp;quot;Offset&amp;amp;amp;quot;] != &amp;amp;amp;quot;undefined&amp;amp;amp;quot;) 
a[type.toLowerCase()] = window[&amp;amp;amp;quot;page&amp;amp;amp;quot; + b + &amp;amp;amp;quot;Offset&amp;amp;amp;quot;];
            else {
b = document.documentElement.clientHeight ? document.documentElement: document.body;
                a[type.toLowerCase()] = b[&amp;amp;amp;quot;scroll&amp;amp;amp;quot; + type]
            }
        }
        return a
    }
    function l() {
        var a = document.body,
        b;
        if (window.innerHeight) b = window.innerHeight;
        else if (a.parentElement.clientHeight) b = a.parentElement.clientHeight;
        else if (a &amp;amp;amp;amp;&amp;amp;amp;amp; a.clientHeight) b = a.clientHeight;
        return b
    }
    function i(a) {
        this.parent = document.body;
        this.createEl(this.parent, a);
        this.size = Math.random() * 5 + 5;
        this.el.style.width = Math.round(this.size) + &amp;amp;amp;quot;px&amp;amp;amp;quot;;
        this.el.style.height = Math.round(this.size) + &amp;amp;amp;quot;px&amp;amp;amp;quot;;
        this.maxLeft = document.body.offsetWidth - this.size;
        this.maxTop = document.body.offsetHeight - this.size;
        this.left = Math.random() * this.maxLeft;
        this.top = h().top + 1;
        this.angle = 1.4 + 0.2 * Math.random();
        this.minAngle = 1.4;
        this.maxAngle = 1.6;
        this.angleDelta = 0.01 * Math.random();
        this.speed = 2 + Math.random()
    }
    var j = false;
    g(function() {
        j = true
    });
    var f = true;
    window.createSnow = function(a, b) {
        if (j) {
            var c = [],
            m = setInterval(function() {
                f &amp;amp;amp;amp;&amp;amp;amp;amp; b &amp;amp;amp;gt; c.length &amp;amp;amp;amp;&amp;amp;amp;amp; Math.random() 
&amp;amp;amp;lt; b * 0.0025 &amp;amp;amp;amp;&amp;amp;amp;amp; c.push(new i(a)); ! f &amp;amp;amp;amp;&amp;amp;amp;amp; !c.length &amp;amp;amp;amp;&amp;amp;amp;amp; clearInterval(m);
                for (var e = h().top, n = l(), d = c.length - 1; d &amp;amp;amp;gt;= 0; d--) 
if (c[d]) if (c[d].top &amp;amp;amp;lt; e || c[d].top + c[d].size + 1 &amp;amp;amp;gt; e + n) {
                    c[d].remove();
                    c[d] = null;
                    c.splice(d, 1)
                } else {
                    c[d].move();
                    c[d].draw()
                }
            },
            40);
            k(window, &amp;amp;amp;quot;scroll&amp;amp;amp;quot;,
            function() {
                for (var e = c.length - 1; e &amp;amp;amp;gt;= 0; e--) c[e].draw()
            })
        } else g(function() {
            createSnow(a, b)
        })
    };
    window.removeSnow = function() {
        f = false
    };
    i.prototype = {
        createEl: function(a, b) {
            this.el = document.createElement(&amp;amp;amp;quot;img&amp;amp;amp;quot;);
            this.el.setAttribute
(&amp;amp;amp;quot;src&amp;amp;amp;quot;, b + &amp;amp;amp;quot;http://mimg.127.net/hxm/quan/hd/111207_sdj/style/img/snow.gif&amp;amp;amp;quot;);
            this.el.style.position = &amp;amp;amp;quot;absolute&amp;amp;amp;quot;;
            this.el.style.display = &amp;amp;amp;quot;block&amp;amp;amp;quot;;
            this.el.style.zIndex = &amp;amp;amp;quot;99999&amp;amp;amp;quot;;
            this.parent.appendChild(this.el)
        },
        move: function() {
            if (this.angle &amp;amp;amp;lt; this.minAngle || this.angle &amp;amp;amp;gt; this.maxAngle) 
this.angleDelta = -this.angleDelta;
            this.angle += this.angleDelta;
            this.left += this.speed * Math.cos(this.angle * Math.PI);
            this.top -= this.speed * Math.sin(this.angle * Math.PI);
            if (this.left &amp;amp;amp;lt; 0) this.left = this.maxLeft;
            else if (this.left &amp;amp;amp;gt; this.maxLeft) this.left = 0
        },
        draw: function() {
            this.el.style.top = Math.round(this.top) + &amp;amp;amp;quot;px&amp;amp;amp;quot;;
            this.el.style.left = Math.round(this.left) + &amp;amp;amp;quot;px&amp;amp;amp;quot;
        },
        remove: function() {
            this.parent.removeChild(this.el);
            this.parent = this.el = null
        }
    }
})();
createSnow(&amp;amp;amp;quot;&amp;amp;amp;quot;, 40);
&amp;amp;amp;lt;/script&amp;amp;amp;gt;

其中createSnow(“”, 40);是改变雪花密度,this.size = Math.random() * 5 + 5;是雪片大小参数大家可以适当修改参数来达到自己最想要的效果
由于小站是浅色系的主题,所以不是很明显,如果是深色系的话会很好看的呢

发表评论

电子邮件地址不会被公开。 必填项已用*标注