Last active
August 29, 2015 14:01
-
-
Save z-------------/990955927bed7b3e36e9 to your computer and use it in GitHub Desktop.
Get mouse coordinates with mouse.coords object. The script handles the event for you.
This file contains hidden or 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
| var mouse = {}; | |
| mouse.coords = {x:-1,y:-1}; | |
| window.addEventListener("mousemove",function(e){ | |
| mouse.coords.x = e.clientX; | |
| mouse.coords.y = e.clientY; | |
| }); | |
| /* example: | |
| if (mouse.coords.x > window.innerWidth / 2) { | |
| console.log("The mouse is in the right half!") | |
| } else { | |
| console.log("The mouse is in the left half!") | |
| } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment