Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
html, body { background: #323c46; } .ref-img { position: fixed; top: 0; left: 0; z-index: 1; width: 150px; height: auto; } .canvas { position: absolute; z-index: 0; } .rng-spacing { position: absolute; z-index: 1; right: 20px; top: 20px; } .codepen-link { position: absolute; right: 30px; bottom: 30px; height: 40px; width: 40px; z-index: 10; border-radius: 50%; background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/544318/logo.jpg"); background-position: center center; background-size: cover; opacity: 0.5; -webkit-transition: all 0.25s; transition: all 0.25s; } .codepen-link:hover { opacity: 1; box-shadow: 0 2px 6px rgba(20, 20, 20, 0.8); }
JavaScript
const canvas = { main: document.querySelector('.canvas'), os: document.createElement('canvas') }; const ctx = { main: canvas.main.getContext('2d'), os: canvas.os.getContext('2d') }; let config = { spacing: 8, width: 0, height: 0 }, particles = []; class Particle { constructor(x, y) { this.color = ``; this.speed = 4 * Math.random() + 1; this.previousPosition = { x: x, y: y }; this.position = { x: x, y: y }; this.velocity = { x: 0, y: 0 }; } update() { let data = ctx.os.getImageData(this.position.x, this.position.y, 1, 1).data, theta = ((data[0] + data[1] + data[2]) / 765) * 2 * Math.PI; this.color = `rgb(${data[0]},${data[1]},${data[2]})`; this.velocity.x = Math.cos(theta) * this.speed; this.velocity.y = Math.sin(theta) * this.speed; this.previousPosition.x = this.position.x; this.previousPosition.y = this.position.y; this.position.x += this.velocity.x; this.position.y += this.velocity.y; } } function init() { let img = new Image(); img.src = `${document.querySelector('.ref-img').src}?d=8675309`; img.crossOrigin = 'anonymous'; img.onload = () => { config.width = img.width; config.height = img.height; canvas.main.width = canvas.os.width = config.width; canvas.main.height = canvas.os.height = config.height; canvas.main.style = ` top: calc(50% - ${config.height * 0.5}px); left: calc(50% - ${config.width * 0.5}px); width: ${config.width}px; height: ${config.height}px; `; ctx.os.drawImage(img, 0, 0); loop(); }; } function loop() { if (particles.length < 1000) { particles.push(new Particle( Math.random() * config.width, Math.random() * config.height )); } for (let i = particles.length - 1; i >= 0; i--) { let p = particles[i]; p.update(); if ( p.position.x > config.width || p.position.x < 0 || p.position.y > config.height || p.position.y < 0 ) { particles.splice(i, 1); continue; } else { ctx.main.globalCompositeOperation = 'lighten'; ctx.main.strokeStyle = p.color; ctx.main.fillStyle = p.color; ctx.main.fillRect(p.position.x, p.position.y, 1, 1); ctx.main.beginPath(); ctx.main.moveTo(p.previousPosition.x, p.previousPosition.y); ctx.main.lineTo(p.position.x, p.position.y); ctx.main.stroke(); ctx.main.closePath(); } } window.requestAnimationFrame(loop); } window.onload = init;
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>颗粒涂料-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号