-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (23 loc) · 1.12 KB
/
script.js
File metadata and controls
30 lines (23 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
document.addEventListener('mousemove', function(e) {
const trail = document.createElement('div');
trail.className = 'trail';
document.body.appendChild(trail);
const rect = trail.getBoundingClientRect();
const offsetX = rect.width / 2;
const offsetY = rect.height / 2;
trail.style.left = `${e.pageX - offsetX}px`;
trail.style.top = `${e.pageY - offsetY}px`;
setTimeout(function() {
trail.remove();
}, 150);
const randomColorTrail = document.createElement('div');
randomColorTrail.className = 'trail';
document.body.appendChild(randomColorTrail);
randomColorTrail.style.left = `${e.pageX - offsetX}px`;
randomColorTrail.style.top = `${e.pageY - offsetY}px`;
randomColorTrail.style.background = `radial-gradient(circle, rgba(${Math.random()*255},${Math.random()*255},${Math.random()*255},0.9) 0%, rgba(${Math.random()*255},${Math.random()*255},${Math.random()*255},0.6) 50%, rgba(${Math.random()*255},${Math.random()*255},${Math.random()*255},0) 100%)`;
setTimeout(function() {
randomColorTrail.remove();
}, 250);
});
//newly updated