Created
September 14, 2018 10:03
-
-
Save LucaRosaldi/8dbf656a59a6d71c4b6f843f6025f166 to your computer and use it in GitHub Desktop.
JS: Update mouse position CSS var
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:root { | |
--mouse-x: 0px; | |
--mouse-y: 0px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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