mousemove javascript code example
Example 1: Javascript track mouse pointer
var pointerX = -1;
var pointerY = -1;
document.onmousemove = function(event) {
pointerX = event.pageX;
pointerY = event.pageY;
}
setInterval(pointerCheck, 1000);
function pointerCheck() {
console.log('Cursor at: '+pointerX+', '+pointerY);
}
Example 2: javascript canvas mousemove
var canv = document.getElementById('my_canvas');
canv.addEventListener('mousemove', e => {
console.log({x:e.offsetX, y:e.offsetY, z:e})
});
var canv = document.getElementById('my_canvas');
canv.addEventListener('touchmove', e => {
ee = e.touches[0];
console.log({x:ee.clientX, y:ee.clientY, z:e})
});
Example 3: mousemove jquery
$( "#target" ).mousemove(function( event ) {
});
Example 4: javascript mouse up mouse down
<p id="myP" onmousedown="mouseDown()" onmouseup="mouseUp()">
<script>
function mouseDown() {
}
function mouseUp() {
}
</script>