WordPress美化 - 下雪特效

马上就要过年了,今天来分享一个下雪的美化特效。

具体教程

该js文件已支持https,同时已将其及相关雪花图片进行CDN加速处理,可直接调用。

找到WordPress主题的footer.php文件,在末尾</body>上方(这样可以最后加载特效,以免影响其他内容的访问速度),添加以下代码:

<script type="text/javascript" src="https://api.dujin.org/js/xiaxue/xiaxue.js"></script>

保存上传/替换/覆盖即可。

如果有缓存的小伙伴记得清理下缓存(静态文件缓存、页面缓存、CDN缓存、内存缓存等)。

懂前端的同学可以直接将js代码添加到源码中即可:

(function() {
    function k(a, b, c) {
        if (a.addEventListener) a.addEventListener(b, c, false);
        else a.attachEvent && a.attachEvent("on" + b, c)
    }

    function g(a) {
        if (typeof window.onload != "function") window.onload = a;
        else {
            var b = window.onload;
            window.onload = function() {
                b();
                a()
            }
        }
    }

    function h() {
        var a = {};
        for (type in {
            Top: "",
            Left: ""
        }) {
            var b = type == "Top" ? "Y" : "X";
            if (typeof window["page" + b + "Offset"] != "undefined")
                a[type.toLowerCase()] = window["page" + b + "Offset"];
            else {
                b = document.documentElement.clientHeight ? document.documentElement : document.body;
                a[type.toLowerCase()] = b["scroll" + 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 && a.clientHeight) b = a.clientHeight;
        return b
    }

    function i(a) {
        this.parent = document.body;
        this.createEl(this.parent, a);
        this.size = Math.random() * 10 + 15; /* 两个数字控制雪花的大小,目前代码控制雪花尺寸为10~25px */
        this.el.style.width = Math.round(this.size) + "px";
        this.el.style.height = Math.round(this.size) + "px";
        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 && b > c.length && Math.random() < b * 0.0025 && c.push(new i(a));
                    !f && !c.length && clearInterval(m);
                    for (var e = h().top, n = l(), d = c.length - 1; d >= 0; d--)
                        if (c[d]) if (c[d].top < e || c[d].top + c[d].size + 1 > e + n) {
                                c[d].remove();
                                c[d] = null;
                                c.splice(d, 1)
                            } else {
                                c[d].move();
                                c[d].draw()
                            }
                },
                    40);
            k(window, "scroll", function() {
                for (var e = c.length - 1; e >= 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("img");
            this.el.setAttribute("src", b + "https://api.dujin.org/js/xiaxue/" + Math.floor(Math.random() * 4) + ".gif"); /* 注意修改为四个雪花文件所在的目录地址 */
            this.el.style.position = "absolute";
            this.el.style.display = "block";
            this.el.style.zIndex = "99999";
            this.parent.appendChild(this.el)
        },
        move: function() {
            if (this.angle < this.minAngle || this.angle > 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 < 0) this.left = this.maxLeft;
            else if (this.left > this.maxLeft) this.left = 0
        },
        draw: function() {
            this.el.style.top = Math.round(this.top) + "px";
            this.el.style.left = Math.round(this.left) + "px"
        },
        remove: function() {
            this.parent.removeChild(this.el);
            this.parent = this.el = null
        }
    }
})();
createSnow("", 40);

给TA买糖
共{{data.count}}人
人已赞赏
WordPress美化

WordPress美化 - 鼠标点击烟花特效

2020-10-26 0:00:00

服务器与web应用

常见搜索引擎蜘蛛与需屏蔽蜘蛛

2020-9-20 8:00:00

⚠️
恩月阁文章由星九进行编写或整理,部分内容来源于互联网,仅供网友学习交流,若您喜欢本文可附上原文链接随意转载。
若无意中侵害到您的权益,请发送邮件至 xingjiu@nuue.cn 或点击右侧 私信:星九 反馈,我们将尽快处理。
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索