js 气泡上升和鼠标点击事件

news2024/9/25 22:37:45

效果图

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <style>
            body {
                padding: 0;
                margin: 0;
                background: #000;
            }
        </style>
    </head>
    <body>
        <div id="clickCanvas" style=" position:fixed;left:0;top:0;z-index:1;pointer-events:none;"></div>
        <canvas id="header_canvas" style="position: absolute; z-index:12;bottom: 0"></canvas>
    </body>
    <!-- 鼠标点击 -->
    <script>
        /* Copyright (C) 2013 Justin Windle sketch.min.js, http://soulwire.co.uk */
        var Sketch = (function() {
            'use strict';
            function e(e) {
                return '[object Array]' == Object.prototype.toString.call(e);
            }
            function t(e) {
                return 'function' == typeof e;
            }
            function n(e) {
                return 'number' == typeof e;
            }
            function o(e) {
                return 'string' == typeof e;
            }
            function r(e) {
                return E[e] || String.fromCharCode(e);
            }
            function i(e, t, n) {
                for (var o in t) (n || !e.hasOwnProperty(o)) && (e[o] = t[o]);
                return e;
            }
            function u(e, t) {
                return function() {
                    e.apply(t, arguments);
                };
            }
            function a(e) {
                var n = {};
                for (var o in e) n[o] = t(e[o]) ? u(e[o], e) : e[o];
                return n;
            }
            function c(e) {
                function n(n) {
                    t(n) && n.apply(e, [].splice.call(arguments, 1));
                }
                function u(e) {
                    for (_ = 0; _ < J.length; _++) (G = J[_]), o(G) ? O[(e ? 'add' : 'remove') + 'EventListener'].call(O, G, k, !1) : t(G) ? (k = G) : (O = G);
                }
                function c() {
                    L(T), (T = I(c)), U || (n(e.setup), (U = t(e.setup)), n(e.resize)), e.running && !j && ((e.dt = (B = +new Date()) - e.now), (e.millis += e.dt), (e.now = B), n(e.update), e.autoclear && K && e.clear(), n(e.draw)), (j = ++j % e.interval);
                }
                function l() {
                    (O = Y ? e.style : e.canvas), (D = Y ? 'px' : ''), e.fullscreen && ((e.height = w.innerHeight), (e.width = w.innerWidth)), (O.height = e.height + D), (O.width = e.width + D), e.retina && K && X && ((O.height = e.height * X), (O.width = e.width * X), (O.style.height = e.height + 'px'), (O.style.width = e.width + 'px'), e.scale(X, X)), U && n(e.resize);
                }
                function s(e, t) {
                    return (N = t.getBoundingClientRect()), (e.x = e.pageX - N.left - w.scrollX), (e.y = e.pageY - N.top - w.scrollY), e;
                }
                function f(t, n) {
                    return s(t, e.element), (n = n || {}), (n.ox = n.x || t.x), (n.oy = n.y || t.y), (n.x = t.x), (n.y = t.y), (n.dx = n.x - n.ox), (n.dy = n.y - n.oy), n;
                }
                function g(e) {
                    if ((e.preventDefault(), (W = a(e)), (W.originalEvent = e), W.touches)) for (M.length = W.touches.length, _ = 0; _ < W.touches.length; _++) M[_] = f(W.touches[_], M[_]);
                    else (M.length = 0), (M[0] = f(W, V));
                    return i(V, M[0], !0), W;
                }
                function h(t) {
                    for (t = g(t), q = (Q = J.indexOf((z = t.type))) - 1, e.dragging = /down|start/.test(z) ? !0 : /up|end/.test(z) ? !1 : e.dragging; q; ) o(J[q]) ? n(e[J[q--]], t) : o(J[Q]) ? n(e[J[Q++]], t) : (q = 0);
                }
                function p(t) {
                    (F = t.keyCode), (H = 'keyup' == t.type), (Z[F] = Z[r(F)] = !H), n(e[t.type], t);
                }
                function v(t) {
                    e.autopause && ('blur' == t.type ? b : C)(), n(e[t.type], t);
                }
                function C() {
                    (e.now = +new Date()), (e.running = !0);
                }
                function b() {
                    e.running = !1;
                }
                function P() {
                    (e.running ? b : C)();
                }
                function A() {
                    K && e.clearRect(0, 0, e.width, e.height);
                }
                function S() {
                    (R = e.element.parentNode), (_ = x.indexOf(e)), R && R.removeChild(e.element), ~_ && x.splice(_, 1), u(!1), b();
                }
                var T,
                    k,
                    O,
                    R,
                    N,
                    _,
                    D,
                    B,
                    G,
                    W,
                    z,
                    F,
                    H,
                    q,
                    Q,
                    j = 0,
                    M = [],
                    U = !1,
                    X = w.devicePixelRatio,
                    Y = e.type == m,
                    K = e.type == d,
                    V = { x: 0, y: 0, ox: 0, oy: 0, dx: 0, dy: 0 },
                    J = [e.element, h, 'mousedown', 'touchstart', h, 'mousemove', 'touchmove', h, 'mouseup', 'touchend', h, 'click', y, p, 'keydown', 'keyup', w, v, 'focus', 'blur', l, 'resize'],
                    Z = {};
                for (F in E) Z[E[F]] = !1;
                return i(e, { touches: M, mouse: V, keys: Z, dragging: !1, running: !1, millis: 0, now: 0 / 0, dt: 0 / 0, destroy: S, toggle: P, clear: A, start: C, stop: b }), x.push(e), e.autostart && C(), u(!0), l(), c(), e;
            }
            for (
                var l,
                    s,
                    f = 'E LN10 LN2 LOG2E LOG10E PI SQRT1_2 SQRT2 abs acos asin atan ceil cos exp floor log round sin sqrt tan atan2 pow max min'.split(' '),
                    g = '__hasSketch',
                    h = Math,
                    d = 'canvas',
                    p = 'webgl',
                    m = 'dom',
                    y = document,
                    w = window,
                    x = [],
                    v = { fullscreen: !0, autostart: !0, autoclear: !0, autopause: !0, container: y.body, interval: 1, globals: !0, retina: !1, type: d },
                    E = { 8: 'BACKSPACE', 9: 'TAB', 13: 'ENTER', 16: 'SHIFT', 27: 'ESCAPE', 32: 'SPACE', 37: 'LEFT', 38: 'UP', 39: 'RIGHT', 40: 'DOWN' },
                    C = {
                        CANVAS: d,
                        WEB_GL: p,
                        WEBGL: p,
                        DOM: m,
                        instances: x,
                        install: function(t) {
                            if (!t[g]) {
                                for (var o = 0; o < f.length; o++) t[f[o]] = h[f[o]];
                                i(t, {
                                    TWO_PI: 2 * h.PI,
                                    HALF_PI: h.PI / 2,
                                    QUATER_PI: h.PI / 4,
                                    random: function(t, o) {
                                        return e(t) ? t[~~(h.random() * t.length)] : (n(o) || ((o = t || 1), (t = 0)), t + h.random() * (o - t));
                                    },
                                    lerp: function(e, t, n) {
                                        return e + n * (t - e);
                                    },
                                    map: function(e, t, n, o, r) {
                                        return ((e - t) / (n - t)) * (r - o) + o;
                                    }
                                }),
                                    (t[g] = !0);
                            }
                        },
                        create: function(e) {
                            return (
                                (e = i(e || {}, v)),
                                e.globals && C.install(self),
                                (l = e.element = e.element || y.createElement(e.type === m ? 'div' : 'canvas')),
                                (s = e.context =
                                    e.context ||
                                    (function() {
                                        switch (e.type) {
                                            case d:
                                                return l.getContext('2d', e);
                                            case p:
                                                return l.getContext('webgl', e) || l.getContext('experimental-webgl', e);
                                            case m:
                                                return (l.canvas = l);
                                        }
                                    })()),
                                e.container.appendChild(l),
                                C.augment(s, e)
                            );
                        },
                        augment: function(e, t) {
                            return (t = i(t || {}, v)), (t.element = e.canvas || e), (t.element.className += ' sketch'), i(e, t, !0), c(e);
                        }
                    },
                    b = ['ms', 'moz', 'webkit', 'o'],
                    P = self,
                    A = 0,
                    S = 'AnimationFrame',
                    T = 'request' + S,
                    k = 'cancel' + S,
                    I = P[T],
                    L = P[k],
                    O = 0;
                O < b.length && !I;
                O++
            )
                (I = P[b[O] + 'Request' + S]), (L = P[b[O] + 'Cancel' + T]);
            return (
                (P[T] = I =
                    I ||
                    function(e) {
                        var t = +new Date(),
                            n = h.max(0, 16 - (t - A)),
                            o = setTimeout(function() {
                                e(t + n);
                            }, n);
                        return (A = t + n), o;
                    }),
                (P[k] = L =
                    L ||
                    function(e) {
                        clearTimeout(e);
                    }),
                C
            );
        })();

        //---
        if (document.getElementById('clickCanvas')) {
            function Particle(x, y, radius) {
                this.init(x, y, radius);
            }
            Particle.prototype = {
                init: function(x, y, radius) {
                    this.alive = true;
                    this.radius = radius || 10;
                    this.wander = 0.15;
                    this.theta = random(TWO_PI);
                    this.drag = 0.92;
                    this.color = '#ffeb3b';

                    this.x = x || 0.0;
                    this.y = y || 0.0;
                    this.vx = 0.0;
                    this.vy = 0.0;
                },
                move: function() {
                    this.x += this.vx;
                    this.y += this.vy;
                    this.vx *= this.drag;
                    this.vy *= this.drag;
                    this.theta += random(-0.5, 0.5) * this.wander;
                    this.vx += sin(this.theta) * 0.1;
                    this.vy += cos(this.theta) * 0.1;
                    this.radius *= 0.96;
                    this.alive = this.radius > 0.5;
                },
                draw: function(ctx) {
                    ctx.beginPath();
                    ctx.arc(this.x, this.y, this.radius, 0, TWO_PI);
                    ctx.fillStyle = this.color;
                    ctx.fill();
                }
            };
            var MAX_PARTICLES = 50;
            //圆点颜色库
            var COLOURS = ['#5ee4ff', '#f44033', '#ffeb3b', '#F38630', '#FA6900', '#f403e8', '#F9D423'];
            var particles = [];
            var pool = [];
            var clickparticle = Sketch.create({
                container: document.getElementById('clickCanvas')
            });
            clickparticle.spawn = function(x, y) {
                if (particles.length >= MAX_PARTICLES) pool.push(particles.shift());
                particle = pool.length ? pool.pop() : new Particle();
                particle.init(x, y, random(5, 20)); //圆点大小范围
                particle.wander = random(0.5, 2.0);
                particle.color = random(COLOURS);
                particle.drag = random(0.9, 0.99);
                theta = random(TWO_PI);
                force = random(1, 5);
                particle.vx = sin(theta) * force;
                particle.vy = cos(theta) * force;
                particles.push(particle);
            };
            clickparticle.update = function() {
                var i, particle;
                for (i = particles.length - 1; i >= 0; i--) {
                    particle = particles[i];
                    if (particle.alive) particle.move();
                    else pool.push(particles.splice(i, 1)[0]);
                }
            };
            clickparticle.draw = function() {
                clickparticle.globalCompositeOperation = 'lighter';
                for (var i = particles.length - 1; i >= 0; i--) {
                    particles[i].draw(clickparticle);
                }
            };
            //按下时显示效果,mousedown 换成 click 为点击时显示效果(我用的 click)
            document.addEventListener('mousedown', function(e) {
                var max, j;
                //排除一些元素
                'TEXTAREA' !== e.target.nodeName &&
                    'INPUT' !== e.target.nodeName &&
                    'A' !== e.target.nodeName &&
                    'I' !== e.target.nodeName &&
                    'IMG' !== e.target.nodeName &&
                    (function() {
                        for (max = random(15, 20), j = 0; j < max; j++) clickparticle.spawn(e.clientX, e.clientY);
                    })();
            });
        }
    </script>

    <!-- 气泡上升 -->
    <script>
        /* Copyright (C) 2019 一为忆 bubble.js, http://www.iowen.cn */
        (function() {
            var canvas,
                ctx,
                width,
                height,
                bubbles,
                animateHeader = true;
            initHeader();
            function initHeader() {
                canvas = document.getElementById('header_canvas');
                window_resize();
                ctx = canvas.getContext('2d');
                //建立泡泡
                bubbles = [];
                var num = width * 0.04; //气泡数量
                for (var i = 0; i < num; i++) {
                    var c = new Bubble();
                    bubbles.push(c);
                }
                animate();
            }
            function animate() {
                if (animateHeader) {
                    ctx.clearRect(0, 0, width, height);
                    for (var i in bubbles) {
                        bubbles[i].draw();
                    }
                }
                requestAnimationFrame(animate);
            }
            function window_resize() {
                //canvas铺满窗口
                width = window.innerWidth;
                height = window.innerHeight;

                // //如果需要铺满内容可以换下面这个
                // var panel = document.getElementById('thumbnail_canvas');
                // width=panel.offsetWidth;
                // height=panel.offsetHeight;

                canvas.width = width;
                canvas.height = height;
            }
            window.onresize = function() {
                window_resize();
            };
            function Bubble() {
                var _this = this;
                (function() {
                    _this.pos = {};
                    init();
                })();
                function init() {
                    _this.pos.x = Math.random() * width;
                    _this.pos.y = height + Math.random() * 100;
                    _this.alpha = 0.1 + Math.random() * 0.3; //气泡透明度
                    _this.alpha_change = 0.0002 + Math.random() * 0.0005; //气泡透明度变化速度
                    _this.scale = 0.2 + Math.random() * 0.5; //气泡大小
                    _this.scale_change = Math.random() * 0.002; //气泡大小变化速度
                    _this.speed = 0.1 + Math.random() * 0.4; //气泡上升速度
                }
                //气泡
                this.draw = function() {
                    if (_this.alpha <= 0) {
                        init();
                    }
                    _this.pos.y -= _this.speed;
                    _this.alpha -= _this.alpha_change;
                    _this.scale += _this.scale_change;
                    ctx.beginPath();
                    ctx.arc(_this.pos.x, _this.pos.y, _this.scale * 10, 0, 2 * Math.PI, false);
                    ctx.fillStyle = 'rgba(255,255,255,' + _this.alpha + ')';
                    ctx.fill();
                };
            }
        })();
    </script>
</html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1074207.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

银河麒麟服务器x86安装ntp客户端,并配置成功可以同步时间

脚本 # 安装ntp客户端 sudo dnf install chrony # 配置 pool 2.centos.pool.ntp.org iburst给这一行加注释 sudo sed -i s/^pool 2.centos.pool.ntp.org iburst/#&/ /etc/chrony.conf # 添加3个阿里云NTP服务器 # echo -e "server ntp1.aliyun.com iburst\nserver nt…

安卓 kotlin-supportFragmentManager报红

如果你继承baseActivity 请查看 是不是继承 AppCompatActivity

全网都在找的python+requests接口自动化测试框架实例详解教程

前言 Python是一种功能强大的编程语言&#xff0c;它可以用于自动化测试&#xff0c;特别是接口自动化测试。许多Python库都可以用于接口自动化测试&#xff0c;其中requests库是其中最受欢迎的库之一。 requests库可以用于发送HTTP请求并获取服务器响应&#xff0c;从而轻松…

java案例21:学生管理系统

思路&#xff1a; 编写一个学生管理系统&#xff0c; 实现对学生信息的添加、删除、修改和查询功能。首页&#xff1a; 用于显示系统的所有操作&#xff0c;并根据用户在控制台的输入选择需要使用的功能查询功能&#xff1a; 用户选择后&#xff0c;在控制台打印所有学生信息添…

阿里云服务器公网带宽多少钱1M?

阿里云服务器公网带宽计费模式按固定带宽”计费多少钱1M&#xff1f;地域不同带宽价格不同&#xff0c;北京、杭州、深圳等大陆地域价格是23元/Mbps每月&#xff0c;中国香港1M带宽价格是30元一个月&#xff0c;美国硅谷是30元一个月&#xff0c;日本东京1M带宽是25元一个月&am…

爬虫Python

文章目录 基本数据类型bytes类型python数据类型转换 python运算符&#xff08;必会&#xff01;&#xff01;&#xff01;&#xff09;python数字数学函数&#xff08;必会&#xff01;&#xff01;&#xff01;&#xff09;随机数函数三角函数&#xff08;简&#xff09;数字常…

c++视觉处理---均值滤波

均值滤波 cv::blur()函数是OpenCV中用于应用均值滤波的函数。均值滤波是一种简单的平滑技术&#xff0c;它计算每个像素周围像素的平均值&#xff0c;并用该平均值替代原始像素值。这有助于降低图像中的噪声&#xff0c;并可以模糊图像的细节。 以下是cv::blur()函数的基本用…

记一次 .NET某账本软件 非托管泄露分析

一&#xff1a;背景 1. 讲故事 中秋国庆长假结束&#xff0c;哈哈&#xff0c;在老家拍了很多的短视频&#xff0c;有兴趣的可以上B站观看&#xff1a;https://space.bilibili.com/409524162 &#xff0c;今天继续给大家分享各种奇奇怪怪的.NET生产事故&#xff0c;希望能帮助…

c++视觉处理---高斯滤波

高斯滤波处理 高斯滤波是一种常用的平滑滤波方法&#xff0c;它使用高斯函数的权重来平滑图像。高斯滤波通常用于去除噪声并保留图像中的细节。在OpenCV中&#xff0c;可以使用cv::GaussianBlur()函数来应用高斯滤波。 以下是cv::GaussianBlur()函数的基本用法&#xff1a; …

区块链技术的飞跃: 2023年的数字革命

随着时代的推进和技术的不断创新&#xff0c;2023年成为区块链技术飞跃发展的一年。区块链&#xff0c;一个曾经只是数字货币领域的技术&#xff0c;现在已经逐渐渗透到各个行业&#xff0c;成为推动数字经济发展的重要力量。在这个数字革命的时代&#xff0c;我们探讨区块链技…

纸黄金效率太低不如做现货

如果从字面上的意义去理解&#xff0c;纸黄金就是在账面上交易的黄金&#xff0c;具体来说它是国内银行为客户提供的一种记账式的黄金买卖&#xff0c;交易的记录和买卖的盈亏值&#xff0c;都只会在预先开设的账户上体现&#xff0c;投资过程中不涉及实物黄金的交收。 对于追求…

Docker基础(CentOS 7)

参考资料 hub.docker.com 查看docker官方仓库&#xff0c;需要梯子 Docker命令大全 黑马程序员docker实操教程 &#xff08;黑马讲的真的不错 容器与虚拟机 安装 yum install -y docker Docker服务命令 启动服务 systemctl start docker停止服务 systemctl stop docker重启…

LocalDateTime、LocalDate、Date、String相互转化大全及其注意事项

LocalDateTime、LocalDate、Date、String相互转化大全及其注意事项 一、前言 大家在开发过程中必不可少的和日期打交道&#xff0c;对接别的系统时&#xff0c;时间日期格式不一致&#xff0c;每次都要转化&#xff01; 二、LocalDateTime、LocalDate、Date三者联系 这里先…

二叉搜索树的基础操作

如果对于二叉搜索树不是太清楚&#xff0c;为什么要使用二叉搜索树&#xff1f;作者推荐&#xff1a;二叉搜索树的初步认识_加瓦不加班的博客-CSDN博客 定义节点 static class BSTNode {int key; // 若希望任意类型作为 key, 则后续可以将其设计为 Comparable 接口Object val…

查看本机Arp缓存,以及清除arp缓存

查看Arp缓存目录 Windows 系统使用 winR&#xff0c;输入cmd 在命令窗口输入 arp -a 删除Arp缓存目录 在命令窗口输入 arp -d * 查看主机路由表

js中 for、forEach、for...in、for...of循环的区别和使用

前端面试题库 &#xff08;面试必备&#xff09; 推荐&#xff1a;★★★★★ 地址&#xff1a;前端面试题库 js中 for、forEach、for...in、for...of循环的区别 我们全部以以下数组举例 var arr [1,2,3,4,5];for循环 for(语句 1; 语句 2; 语句 3){} &#xf…

ThreeJS-3D教学八-OBJLoader模型加载+动画

先看效果图&#xff1a; 本篇给大家介绍下模型加载的知识&#xff0c;用到了OBJLoader对应的模型&#xff0c;为了增加趣味性&#xff0c;花了些时间&#xff0c;利用new THREE.Points获取到模型上的点&#xff0c;做了一个动画效果&#xff0c;其实就是操作 Y轴上的点&#x…

[已解决]java-sun.security.validator.ValidatorException: PKIX path building failed

找了好多文章,终于找到个解决办法! 报错详情内容 解决办法 第一种&#xff08;适用于本人解决办法&#xff09;&#xff1a; httpclient-4.5.jar 定时发送http包&#xff0c;忽然有一天报错&#xff0c;http证书变更引起的。 之前的代码 try {CloseableHttpClient httpCli…

多测师肖sir_高级金牌讲师_python之基本使用003

python之基本使用 一、基础使用 1、python中的打印方式 格式&#xff1a;print&#xff08;打印内容&#xff09; 案例&#xff1a;print&#xff08;12&#xff09; 注意点&#xff1a; 打印的对象中&#xff1a;数值可以直接引用&#xff0c;字母或中文要加上引号&#xff08…

Eclipse导入项目之后中文注释乱码

1 问题 Eclipse导入项目之后中文注释乱码。原因&#xff1a;中文乱码的原因是因为编码的关系 2 解决方法 记事本打开查看编码方式 修改eclipse编码方式 在Eclipse中更改文件的编码方式可以通过以下步骤进行&#xff1a; 打开Eclipse&#xff0c;并导航到要更改编码方式的…