javascript - Is it possible to get negative coordinates for mouse movement -
i using function mouse location. receiving negative values logs. not able find scenario in function return negative values.
function mousemovetracker(event) { var dot, eventdoc, doc, body, pagex, pagey; event = event || window.event; if (event.pagex == null && event.clientx != null) { eventdoc = event.target && event.target.ownerdocument || document; doc = eventdoc.documentelement; body = eventdoc.body; event.pagex = event.clientx + (doc && doc.scrollleft || body && body.scrollleft || 0) - (doc && doc.clientleft || body && body.clientleft || 0); event.pagey = event.clienty + (doc && doc.scrolltop || body && body.scrolltop || 0) - (doc && doc.clienttop || body && body.clienttop || 0); } var mm = {x: event.pagex, y: event.pagey, time: date.now()}; }
try this
var x; var y; if (e.pagex || e.pagey) { x = e.pagex; y = e.pagey; } else { x = e.clientx + document.body.scrollleft + document.documentelement.scrollleft; y = e.clienty + document.body.scrolltop + document.documentelement.scrolltop; } x -= gcanvaselement.offsetleft; y -= gcanvaselement.offsettop;
hope helps !
Comments
Post a Comment