15 lines
365 B
JavaScript
15 lines
365 B
JavaScript
|
const root = document.documentElement;
|
||
|
let mouseX = 0;
|
||
|
let mouseY = 0;
|
||
|
|
||
|
document.addEventListener("mousemove", (evt) => {
|
||
|
mouseX = evt.clientX / innerWidth;
|
||
|
mouseY = evt.clientY / innerHeight;
|
||
|
|
||
|
root.style.setProperty("--mouse-x", `${mouseX}`);
|
||
|
root.style.setProperty("--mouse-y", `${mouseY}`);
|
||
|
|
||
|
console.log(root.style.getPropertyValue("--mouse-x"));
|
||
|
});
|
||
|
|