Created
June 14, 2023 15:46
-
-
Save MiniKielbyM/346864204380e511ead28d0ef7102d86 to your computer and use it in GitHub Desktop.
a mouse movement detector
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
let m = false; | |
let id = 'example' | |
const Element = document.getElementById(id) | |
//add an 'onclick' listner with the MouseMove() function | |
function MouseMove() | |
{ | |
if(m==false) | |
{ | |
m=true | |
} | |
if(m==true) | |
{ | |
m=false | |
} | |
} | |
onmousemove = function (e) { | |
console.log("mouse location:", e.clientX, e.clientY); | |
var pos = e; | |
//make sure the element's position attribute is set | |
if(m==true) | |
{ | |
Element.style.top = pos.y | |
Element.style.left = pos.x | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment