Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
*, *:before, *:after { margin: 0; padding: 0; box-sizing: border-box; } body { font-size: 0; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } canvas { background-color: black; } .links { color: white; font-family: Roboto, sans-serif; font-weight: 300; font-size: 16px; position: absolute; bottom: 5px; text-align: center; width: 100%; background-color: transparent; opacity: 0; transition: opacity 0.5s linear; transition-delay: 0.5s; } @media (max-width: 370px) { .links { font-size: 13px; } } .links--visible { opacity: 1; } a { color: white; } a:active, a:hover { color: #BB3BA7; }
JavaScript
const parameters = { particleRadius: 2, speed: 0.5, deceleration: 0.05, maxLife: 1200, particlesCount: 4, tIncrement: 0.15, stepPeriod: 30 }; const canvas = document.querySelector('canvas'); const canvasCtx = canvas.getContext('2d'); const setCanvasSize = () => { canvas.width = window.innerWidth; canvas.height = window.innerHeight; }; window.addEventListener('resize', setCanvasSize); setCanvasSize(); let particles = []; let lastRafCall = 0; class Particle { constructor(x, y) { const {maxLife, radius, speed, colors, deceleration} = parameters; this.framesCount = Math.ceil(maxLife / (1000 / 60)); this.framesRendered = 0; this.opacity = 1; this.opacitySpeed = 1 / this.framesCount; this.x = x; this.y = y; this.deceleration = deceleration; //percentage of speed lost each frame if (Math.random() > 0.8) { this.color = '#BB3BA7'; } else { this.color = '#fff'; } this.speedX = random(-speed, speed); this.speedY = random(-speed, speed); this.radius = parameters.particleRadius; this.radiusSpeed = this.radius / this.framesCount; } frame(canvasCtx) { canvasCtx.fillStyle = this.color; canvasCtx.globalAlpha = this.opacity; canvasCtx.beginPath(); canvasCtx.arc(this.x, this.y, this.radius, 0, 2 * Math.PI); canvasCtx.fill(); this.opacity-= this.opacitySpeed; if (this.opacity < 0) { this.opacity = 0; } this.x += this.speedX; this.y += this.speedY; this.speedX *= (1 - this.deceleration); this.speedY *= (1 - this.deceleration); this.radius = this.radius - this.radiusSpeed; if (this.radius < 0) { this.radius = 0; } this.framesRendered++; return this.framesCount >= this.framesRendered; } } const particlesFrame = timestamp => { if (timestamp - lastRafCall > 1000 / 65) { canvasCtx.clearRect(0, 0, canvas.width, canvas.height); particles = particles.filter(p => p.frame(canvasCtx)); lastRafCall = timestamp; } window.requestAnimationFrame(particlesFrame); }; particlesFrame(); const random = (min, max) => { return min + Math.random() * (max - min); }; const addParticlesAtPoint = (x, y) => { const newParticles = (new Array(parameters.particlesCount)).fill(0).map(() => new Particle(x, y)); particles.push(...newParticles); }; const getPositionOnCanvas = (x, y) => ({ x: x + window.innerWidth / 2, y: y + window.innerHeight / 2 }); const addParticlesOnAxis = (x, y) => { const {x: realX, y: realY} = getPositionOnCanvas(x, y); addParticlesAtPoint(realX, realY); }; let t = 0; const getScreenScale = () => { return Math.min(window.innerWidth, window.innerHeight) / 5; }; const addParticlesAtNextPoint = () => { if (!document.hidden) { const scale = 2 / (3 - Math.cos(2 * t)) * getScreenScale(); const x = scale * Math.cos(t); const y = scale * Math.sin(2 * t) / 2; t += parameters.tIncrement; addParticlesOnAxis(x, y); } setTimeout(addParticlesAtNextPoint, parameters.stepPeriod); }; addParticlesAtNextPoint(); const LINKS_APPEARANCE_DELAY = 5000; const addTwitterLinkParticles = () => { const count = 30; const y = window.innerHeight - 15; canvasCtx.font = '16px Roboto'; const {width} = canvasCtx.measureText('Check out my other pens and follow me on twitter!'); const firstX = (window.innerWidth - width) / 2; const lastX = window.innerWidth - firstX; const step = (lastX - firstX) / count; const particlePositions = new Array(count).fill(0).map((el, idx) => ({ x: firstX + step * idx, y })); particlePositions.unshift({ x: firstX - step, y }); particlePositions.push({ x: lastX + step, y }); particlePositions.forEach((pos, i) => { setTimeout(() => addParticlesAtPoint(pos.x, pos.y), i * 20); }); document.querySelector('.links').classList.add('links--visible'); }; setTimeout(addTwitterLinkParticles, LINKS_APPEARANCE_DELAY);
粒子
时间
文字
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号