Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body, html { position: absolute; margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #000; user-select: none; } canvas { position: absolute; width: 100%; height: 100%; user-select: none; touch-action: none; content-zooming: none; background: #000; cursor: crosshair; filter: contrast(120%); }
JavaScript
"use strict"; class Head { constructor () { this.x = 0.0; this.y = 0.0; this.radius = 0.0; this.direction = 0.0; this.dDir = 0.0; this.rightOrLeft = false; this.shooted = false; this.color = 0; } shoot (x, y, direction) { this.shooted = true; this.x = x; this.y = y; this.direction = direction; this.dDir = Math.random(); this.radius = Math.random() * 20 + 5; this.rightOrLeft = Math.random() < .5; this.color = `hsl(${Math.floor(Math.random() * 90) - (Math.random() > 0.33 ? 30 : 160)}, 80%, 60%)`; } anim() { if (!this.shooted) { pointer.next = this; return; } this.x += this.radius * Math.cos( this.direction ); this.y += this.radius * Math.sin( this.direction ); ctx.beginPath(); ctx.arc(this.x, this.y, this.radius * 0.5, 0, 2 * Math.PI); ctx.fillStyle = this.color; ctx.fill(); ctx.stroke(); if( this.rightOrLeft ) this.direction -= this.dDir; else this.direction += this.dDir;; this.radius -= .4; if( this.radius <= 0 ) this.shooted = false; } } const canvas = { init() { this.elem = document.querySelector("canvas"); this.resize(); window.addEventListener("resize", () => this.resize(), false); return this.elem.getContext("2d"); }, resize() { this.width = this.elem.width = this.elem.offsetWidth; this.height = this.elem.height = this.elem.offsetHeight; } }; const pointer = { x: 0, y: 0, xb: 0, yb: 0, next: null, frame: 0, move(e, touch) { e.preventDefault(); const pointer = touch ? e.targetTouches[0] : e; this.x = pointer.clientX; this.y = pointer.clientY; this.shoot(this.x, this.y); }, shoot(x, y) { if (!this.next) { this.next = new Head(); heads.push(this.next); } this.frame++; if (!(this.frame % 3)) { ctx.fillStyle = "rgba(8, 8, 8, 0.05)"; ctx.fillRect(0, 0, canvas.width, canvas.height); } this.next.shoot(x, y, Math.atan2(y - this.yb, x - this.xb)); this.next = null; this.xb = x; this.yb = y; }, init(canvas) { canvas.elem.addEventListener("mousemove", e => this.move(e, false), false); canvas.elem.addEventListener("touchmove", e => this.move(e, true), false); } }; const ctx = canvas.init(); pointer.init(canvas); const heads = []; const run = () => { requestAnimationFrame(run); for (const head of heads) head.anim(); } for (let a = 0; a < 2 * Math.PI; a += 0.1) { pointer.shoot( canvas.width * 0.5 + Math.cos(a) * canvas.width * 0.25, canvas.height * 0.5 + Math.sin(a) * canvas.height * 0.25 ); } run();
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>canvas花卉-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号