Skip to content

Commit

Permalink
Update trail.js
Browse files Browse the repository at this point in the history
  • Loading branch information
MastanSayyad committed Jul 7, 2024
1 parent 80975f6 commit 8028b98
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions trail.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
const coords = { x: 0, y: 0 };
const circles = document.querySelectorAll(".circle");
document.addEventListener("DOMContentLoaded", function () {
const coords = { x: 0, y: 0 };
const circles = document.querySelectorAll(".circle");

circles.forEach(function (circle, index) {
circle.x = 0;
circle.y = 0;
});
circles.forEach(function (circle) {
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
});
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;
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})`;
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];
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;
});
x += (nextCircle.x - x) * 0.3;
y += (nextCircle.y - y) * 0.3;
});

requestAnimationFrame(animateCircles);
}
requestAnimationFrame(animateCircles);
}

animateCircles();
animateCircles();
});

0 comments on commit 8028b98

Please sign in to comment.