js实现canvas粒子跟随彩色泡泡动画效果代码

代码语言:html

所属分类:粒子

代码描述:js实现canvas粒子跟随彩色泡泡动画效果代码

代码标签: 粒子 跟随 彩色 泡泡 动画 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            overflow: hidden;
        }

        canvas {
            background-color: black;
            transition: all .2s;
        }
    </style>

</head>

<body>

    <canvas id="canvas" width="1536" height="700"></canvas>
    <script circlewidth="10" id="cvs">
        /** @type {HTMLCanvasElement} */
        // 初始化画板
        const canvas = document.querySelector('#canvas');
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;

        // 初始化画笔
        const cvs = canvas.getContext('2d');
        let CircleArr = [];

        // 实例化对象

        canvas.addEventListener('mousemove', function (ev) {
            let cir = new Circle(ev.pageX, ev.pageY);
            CircleArr.push(cir);
        })

        canvas.addEventListener('touchmove', function (ev) {
            let cir = new Circle(ev.touches[0].clientX, ev.touches[0].clientY);
            CircleArr.push(cir);
        })

        /**
        * 主要参数位置
        */
        function Circle(X, Y) {
            this.X = Math.floor(X);
            this.Y = Math.floor(Y);
            this.speedX.........完整代码请登录后点击上方下载按钮下载查看

网友评论0