Skip to content

Instantly share code, notes, and snippets.

@LucaRosaldi
Created September 14, 2018 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LucaRosaldi/8dbf656a59a6d71c4b6f843f6025f166 to your computer and use it in GitHub Desktop.
Save LucaRosaldi/8dbf656a59a6d71c4b6f843f6025f166 to your computer and use it in GitHub Desktop.
JS: Update mouse position CSS var
:root {
--mouse-x: 0px;
--mouse-y: 0px;
}
const htmlEl = document.documentElement;
htmlEl.addEventListener( 'mousemove', ( event ) => {
htmlEl.style.setProperty( '--mouse-x', event.clientX + 'px' );
htmlEl.style.setProperty( '--mouse-y', event.clientY + 'px' );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment