-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
23 lines (19 loc) · 866 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const pos = { x: 0, y: 0 };
const element = { x: 0, y: 0, width: 0, height: 0 };
const saveCursorPosition = function (x, y) {
pos.x = ((x - element.x) / element.width).toFixed(2);
pos.y = ((y - element.y) / element.height).toFixed(2);
document.documentElement.style.setProperty("--x", pos.x);
document.documentElement.style.setProperty("--y", pos.y);
};
const elementPropObserver = () => {
element.x = document.getElementById("roadmap").offsetLeft;
element.y = document.getElementById("roadmap").offsetTop;
element.width = document.getElementById("roadmap").clientWidth;
element.height = document.getElementById("roadmap").clientHeight;
};
elementPropObserver();
window.addEventListener("resize", elementPropObserver);
document.getElementById("imgcontainer").addEventListener("mousemove", (e) => {
saveCursorPosition(e.clientX, e.clientY);
});