-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d9e29f
commit f43af28
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const coords = { x: 0, y: 0 }; | ||
const circles = document.querySelectorAll(".circle"); | ||
|
||
circles.forEach(function (circle, index) { | ||
circle.x = 0; | ||
circle.y = 0; | ||
}); | ||
|
||
window.addEventListener("mousemove", function (e) { | ||
coords.x = e.pageX; | ||
coords.y = e.pageY - window.scrollY; // Adjust for vertical scroll position | ||
}); | ||
|
||
function animateCircles() { | ||
let x = coords.x; | ||
let y = coords.y; | ||
|
||
circles.forEach(function (circle, index) { | ||
circle.style.left = x - 12 + "px"; | ||
circle.style.top = y - 12 + "px"; | ||
circle.style.transform = `scale(${(circles.length - index) / circles.length})`; | ||
|
||
circle.x = x; | ||
circle.y = y; | ||
|
||
const nextCircle = circles[index + 1] || circles[0]; | ||
x += (nextCircle.x - x) * 0.3; | ||
y += (nextCircle.y - y) * 0.3; | ||
}); | ||
|
||
requestAnimationFrame(animateCircles); | ||
} | ||
|
||
animateCircles(); |