Skip to content

Commit

Permalink
bugfix, indefinite eventlistener
Browse files Browse the repository at this point in the history
  • Loading branch information
marsian83 committed Oct 10, 2023
1 parent 2a3e5fa commit 613bb17
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions website/src/pages/HomePage/components/HowItWorks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ function HowItWorksCard(props) {
const cardRef = useRef();
const glowRef = useRef();

function glowWithMouse(event) {
const cardRect = cardRef.current.getBoundingClientRect();
glowRef.current.style.setProperty("--x", `${event.x - cardRect.x}px`);
glowRef.current.style.setProperty("--y", `${event.y - cardRect.y}px`);
}

useEffect(() => {
window.addEventListener("mousemove", (event) => {
const cardRect = cardRef.current.getBoundingClientRect();
glowRef.current.style.setProperty("--x", `${event.x - cardRect.x}px`);
glowRef.current.style.setProperty("--y", `${event.y - cardRect.y}px`);
});
window.addEventListener("mousemove", glowWithMouse);

return () => window.removeEventListener("mousemove", glowWithMouse);
}, []);

return (
Expand Down

0 comments on commit 613bb17

Please sign in to comment.