网站特效代码(背景彩带以及点击烟花特效)

这两个特效代码都是我找了很久才找到的,但是我没有本地保存代码的习惯,而项目里也暂时不用,所以为了避免遗失,我还是贴到这里吧。

背景彩带:

(function (name, factory) {
   
   
    if (typeof window === "object") {
   
   
        window[name] = factory();
    }
})("Ribbons", function () {
   
   
    var _w = window, _b = document.body, _d = document.documentElement;
    var random = function () {
   
   
        if (arguments.length === 1) {
   
   
            if (Array.isArray(arguments[0])) {
   
   
                var index = Math.round(random(0, arguments[0].length - 1));
                return arguments[0][index];
            }
            return random(0, arguments[0]);
        } else if (arguments.length === 2) {
   
   
            return Math.random() * (arguments[1] - arguments[0]) + arguments[0];
        }
        return 0;
    };
    var screenInfo = function (e) {
   
   
        var width = Math.max(0, _w.innerWidth || _d.clientWidth || _b.clientWidth || 0),
            height = Math.max(0, _w.innerHeight || _d.clientHeight || _b.clientHeight || 0),
            scrollx = Math.max(0, _w.pageXOffset || _d.scrollLeft || _b.scrollLeft || 0) - (_d.clientLeft || 0),
            scrolly = Math.max(0, _w.pageYOffset || _d.scrollTop || _b.scrollTop || 0) - (_d.clientTop || 0);
        return {
   
   
            width: width,
            height: height,
            ratio: width / height,
            centerx: width / 2,
            centery: height / 2,
            scrollx: scrollx,
            scrolly: scrolly
        };
    };
    var mouseInfo = function (e) {
   
   
        var screen = screenInfo(e), mousex = e ? Math.max(0, e.pageX || e.clientX || 0) : 0,
            mousey = e ? Math.max(0, e.pageY || e.clientY || 0) : 0;
        return {
   
   
            mousex: mousex,
            mousey: mousey,
            centerx: mousex - screen.width / 2,
            centery: mousey - screen.height / 2
        };
    };
    var Point = function (x, y) {
   
   
        this.x = 0;
        this.y = 0;
        this.set(x, y);
    };
    Point.prototype = {
   
   
        constructor: Point, set: function (x, y) {
   
   
            this.x = x || 0;
            this.y = y || 0;
        }, copy: function (point) {
   
   
            this.x = point.x || 0;
            this.y = point.y || 0;
            return this;
        }, multiply: function (x, y) {
   
   
            this.x *= x || 1;
            this.y *= y || 1;
            return this;
        }, divide: function (x, y) {
   
   
            this.x /= x || 1;
            this.y /= y || 1;
            return this;
        }, add: function (x, y) {
   
   
            this.x += x || 0;
            this.y += y || 0;
            return this;
        }, subtract: function (x, y) {
   
   
            this.x -= x || 0;
            this.y -= y || 0;
            return this;
        }, clampX: function (min, max) {
   
   
            this.x = Math.max(min, Math.min(this.x, max));
            return this;
        }, clampY: function (min, max) {
   
   
            this.y = Math.max(min, Math.min(this.y, max));
            return this;
        }, flipX: function () {
   
   
            this.x *= -1;
            return 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值