forked from Ctoic/Lisbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
31 lines (23 loc) · 934 Bytes
/
scripts.js
File metadata and controls
31 lines (23 loc) · 934 Bytes
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
31
document.addEventListener("DOMContentLoaded", () => {
const dots = document.querySelectorAll(".dot");
const pacmanContainer = document.querySelector(".pacman-container");
if (!pacmanContainer) return;
let lastLeft = pacmanContainer.getBoundingClientRect().left;
function updateDots() {
const pacmanRect = pacmanContainer.getBoundingClientRect();
const pacmanCenter = pacmanRect.left + pacmanRect.width / 2;
const isMovingForward = pacmanRect.left > lastLeft;
lastLeft = pacmanRect.left;
dots.forEach((dot) => {
const dotRect = dot.getBoundingClientRect();
const dotCenter = dotRect.left + dotRect.width / 2;
if (isMovingForward) {
dot.style.opacity = pacmanCenter > dotCenter ? "0" : "1";
} else {
dot.style.opacity = pacmanCenter < dotCenter ? "0" : "1";
}
});
requestAnimationFrame(updateDots);
}
requestAnimationFrame(updateDots);
});