Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
html, body { margin: 0; } #particle-canvas { width: 100%; height: 100vh; background: linear-gradient(to bottom, rgb(10, 10, 50) 0%,rgb(60, 10, 60) 100%); vertical-align: middle; }
JavaScript
// modified version of random-normal function normalPool(o){var r=0;do{var a=Math.round(normal({mean:o.mean,dev:o.dev}));if(a
=0)return o.pool[a];r++}while(r<100)}function randomNormal(o){if(o=Object.assign({mean:0,dev:1,pool:[]},o),Array.isArray(o.pool)&&o.pool.length>0)return normalPool(o);var r,a,n,e,l=o.mean,t=o.dev;do{r=(a=2*Math.random()-1)*a+(n=2*Math.random()-1)*n}while(r>=1);return e=a*Math.sqrt(-2*Math.log(r)/r),t*e+l} const NUM_PARTICLES = 100; const PARTICLE_SIZE = 0.5; // View heights const SPEED = 10000; // Milliseconds let particles = []; function rand(low, high) { return Math.random() * (high - low) + low; } function createParticle(canvas) { const colour = { r: 255, g: randomNormal({ mean: 125, dev: 20 }), b: 50, a: rand(0, 1), }; return { x: -2, y: -2, diameter: Math.max(0, randomNormal({ mean: PARTICLE_SIZE, dev: PARTICLE_SIZE / 2 })), duration: randomNormal({ mean: SPEED, dev: SPEED * 0.1 }), amplitude: randomNormal({ mean: 16, dev: 2 }), offsetY: randomNormal({ mean: 0, dev: 10 }), arc: Math.PI * 2, startTime: performance.now() - rand(0, SPEED), colour: `rgba(${colour.r}, ${colour.g}, ${colour.b}, ${colour.a})`, } } function moveParticle(particle, canvas, time) { const progress = ((time - particle.startTime) % particle.duration) / particle.duration; return { ...particle, x: progress, y: ((Math.sin(progress * particle.arc) * particle.amplitude) + particle.offsetY), }; } function drawParticle(particle, canvas, ctx) { canvas = document.getElementById('particle-canvas'); const vh = canvas.height / 100; ctx.fillStyle = particle.colour; ctx.beginPath(); ctx.ellipse( particle.x * canvas.width, particle.y * vh + (canvas.height / 2), particle.diameter * vh, particle.diameter * vh, 0, 0, 2 * Math.PI ); ctx.fill(); } function draw(time, canvas, ctx) { // Move particles particles.forEach((particle, index) => { particles[index] = moveParticle(particle, canvas, time); }) // Clear the canvas ctx.clearRect(0, 0, canvas.width, canvas.height); // Draw the particles particles.forEach((particle) => { drawParticle(particle, canvas, ctx); }) // Schedule next frame requestAnimationFrame((time) => draw(time, canvas, ctx)); } function initializeCanvas() { let canvas = document.getElementById('particle-canvas'); canvas.width = canvas.offsetWidth * window.devicePixelRatio; canvas.height = canvas.offsetHeight * window.devicePixelRatio; let ctx = canvas.getContext("2d"); window.addEventListener('resize', () => { canvas.width = canvas.offsetWidth * window.devicePixelRatio; canvas.height = canvas.offsetHeight * window.devicePixelRatio; ctx = canvas.getContext("2d"); }) return [canvas, ctx]; } function startAnimation() { const [canvas, ctx] = initializeCanvas(); // Create a bunch of particles for (let i = 0; i < NUM_PARTICLES; i++) { particles.push(createParticle(canvas)); } requestAnimationFrame((time) => draw(time, canvas, ctx)); }; // Start animation when document is loaded (function () { if (document.readystate !== 'loading') { startAnimation(); } else { document.addEventListener('DOMContentLoaded', () => { startAnimation(); }) } }());
粒子
时间
文字
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号