Skip to content

Instantly share code, notes, and snippets.

@neenjaw
Created January 17, 2018 20:08
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 neenjaw/a6427ea8358ac536cdf46bbd0618e884 to your computer and use it in GitHub Desktop.
Save neenjaw/a6427ea8358ac536cdf46bbd0618e884 to your computer and use it in GitHub Desktop.
JS for setting mouse-x/y css3 variable
var root = document.documentElement;
document.addEventListener("mousemove", evt => {
let x = evt.clientX / innerWidth;
let y = evt.clientY / innerHeight;
root.style.setProperty("--mouse-x", x);
root.style.setProperty("--mouse-y", y);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment