Particle | Effect | Cursor | code in description #Html #css #js #Particle

preview_player
Показать описание
Particle Effect of us html css js

who to use this code

1. open visual studio code
2. create file name html
3. copy and paste
4. run this down show Go Live
Рекомендации по теме
Комментарии
Автор

<!DOCTYPE html> <html> <head> <title>Particle Effect</title> <style> #canvas { border: 1px solid #ddd; } </style> </head> <body> <canvas id="canvas"></canvas> <script> // Get the canvas element const canvas = const ctx = canvas.getContext('2d'); canvas.width = window.innerWidth; canvas.height = window.innerHeight; // Define particle class class Particle { constructor(x, y) { this.x = x; this.y = y; this.velX = Math.random() * 2 - 1; this.velY = Math.random() * 2 - 1; this.size = Math.random() * 2 + 1; this.opacity = Math.random() * 0.5 + 0.5; let particles = []; } update() { this.x += this.velX; this.y += this.velY; this.opacity -= 0.01; } draw() { ctx.beginPath(); ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2); ctx.fillStyle = `rgba(255, 255, 255, ${this.opacity})`; ctx.fill(); } } // Create particles array const particles = []; // Add event listener for mouse move canvas.addEventListener('mousemove', (e) => { const x = e.clientX - canvas.offsetLeft; const y = e.clientY - canvas.offsetTop; for (let i = 0; i < 5; i++) { particles.push(new Particle(x, y)); } }); // Main loop function animate() { ctx.fillStyle = 'rgba(0, 0, 0, 0.1)'; ctx.fillRect(0, 0, canvas.width, canvas.height); for (const particle of particles) { particle.update(); particle.draw(); if (particle.opacity < 0) { particles.splice(particles.indexOf(particle), 1); } } } animate(); </script> </body> </html>

KriDaॐ
join shbcf.ru