Skip to content

Instantly share code, notes, and snippets.

@MiniKielbyM
Created June 14, 2023 15:46
Show Gist options
  • Save MiniKielbyM/346864204380e511ead28d0ef7102d86 to your computer and use it in GitHub Desktop.
Save MiniKielbyM/346864204380e511ead28d0ef7102d86 to your computer and use it in GitHub Desktop.
a mouse movement detector
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