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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -