Update script.js
This commit is contained in:
103
script.js
103
script.js
@@ -468,40 +468,83 @@ function createParticleEffect() {
|
|||||||
setInterval(createParticle, 2000);
|
setInterval(createParticle, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add mouse trail effect
|
// Add mouse trail effect with falling particles
|
||||||
function addMouseTrail() {
|
function addMouseTrail() {
|
||||||
const trail = [];
|
// Particle class for managing individual particles
|
||||||
const trailLength = 20;
|
class Particle {
|
||||||
|
constructor(x, y) {
|
||||||
document.addEventListener('mousemove', function(e) {
|
this.x = x;
|
||||||
const dot = document.createElement('div');
|
this.y = y;
|
||||||
dot.style.position = 'fixed';
|
this.size = Math.random() * 3 + 1; // Random size between 1-4
|
||||||
dot.style.width = '4px';
|
this.speedY = Math.random() * 1 + 0.5; // Random fall speed
|
||||||
dot.style.height = '4px';
|
this.speedX = (Math.random() - 0.5) * 0.5; // Slight horizontal movement
|
||||||
dot.style.background = 'rgba(0, 122, 204, 0.8)';
|
this.opacity = 1;
|
||||||
dot.style.borderRadius = '50%';
|
|
||||||
dot.style.left = e.clientX + 'px';
|
|
||||||
dot.style.top = e.clientY + 'px';
|
|
||||||
dot.style.pointerEvents = 'none';
|
|
||||||
dot.style.zIndex = '9999';
|
|
||||||
dot.style.transition = 'opacity 0.5s ease';
|
|
||||||
|
|
||||||
document.body.appendChild(dot);
|
|
||||||
trail.push(dot);
|
|
||||||
|
|
||||||
if (trail.length > trailLength) {
|
|
||||||
const oldDot = trail.shift();
|
|
||||||
oldDot.style.opacity = '0';
|
|
||||||
setTimeout(() => oldDot.remove(), 500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
update() {
|
||||||
if (dot.parentNode) {
|
this.y += this.speedY;
|
||||||
dot.style.opacity = '0';
|
this.x += this.speedX;
|
||||||
setTimeout(() => dot.remove(), 500);
|
this.opacity -= 0.01;
|
||||||
}
|
}
|
||||||
}, 100);
|
|
||||||
|
draw(ctx) {
|
||||||
|
ctx.fillStyle = `rgba(255, 255, 255, ${this.opacity})`;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
|
||||||
|
ctx.fill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
document.body.appendChild(canvas);
|
||||||
|
|
||||||
|
canvas.style.position = 'fixed';
|
||||||
|
canvas.style.top = '0';
|
||||||
|
canvas.style.left = '0';
|
||||||
|
canvas.style.pointerEvents = 'none';
|
||||||
|
canvas.style.zIndex = '1000';
|
||||||
|
|
||||||
|
function resizeCanvas() {
|
||||||
|
canvas.width = window.innerWidth;
|
||||||
|
canvas.height = window.innerHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('resize', resizeCanvas);
|
||||||
|
resizeCanvas();
|
||||||
|
|
||||||
|
let particles = [];
|
||||||
|
let mouseX = 0;
|
||||||
|
let mouseY = 0;
|
||||||
|
|
||||||
|
// Track mouse position
|
||||||
|
document.addEventListener('mousemove', (e) => {
|
||||||
|
mouseX = e.clientX;
|
||||||
|
mouseY = e.clientY;
|
||||||
|
|
||||||
|
// Create new particles at mouse position
|
||||||
|
if (Math.random() > 0.5) { // Reduce particle creation rate
|
||||||
|
particles.push(new Particle(mouseX, mouseY));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function animate() {
|
||||||
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
// Update and draw particles
|
||||||
|
particles = particles.filter(particle => {
|
||||||
|
particle.update();
|
||||||
|
particle.draw(ctx);
|
||||||
|
return particle.opacity > 0 &&
|
||||||
|
particle.y < canvas.height &&
|
||||||
|
particle.x > 0 &&
|
||||||
|
particle.x < canvas.width;
|
||||||
|
});
|
||||||
|
|
||||||
|
requestAnimationFrame(animate);
|
||||||
|
}
|
||||||
|
|
||||||
|
animate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user