Jump to content

addEventListener() as captureEvents deprecated


freelance84

Recommended Posts

Good morning...

 

I have developed a JS function for a site which works perfectly well, however it requires the coordinates of the mouse to be able to function properly. After some digging i got the following bit of script to track the mouse:

 

/*capturing the mouse coordinates within the window*/
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)  /********LINE IN QUESTION**********/
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
      tempX = event.clientX + document.body.scrollLeft;
      tempY = event.clientY + document.body.scrollTop;
   }
   else {  // grab the x-y pos.s if browser is NS
      tempX = e.pageX;
      tempY = e.pageY;
   }  
   if (tempX < 0){tempX = 0;}
   if (tempY < 0){tempY = 0;}  
}

 

It works like a charm and i so far haven't found it fault on any browsers, however the 'LINE IN QUESTION' uses "captureEvents" which is (as FF is telling me) deprecated, and that i should be using, addEventListener():

 

Use of captureEvents() is deprecated. To upgrade your code, use the DOM 2 addEventListener() method. For more help http://developer.mozilla.org/en/docs/DOM:element.addEventListener

 

The problem is i cant find an easy to understand tutorial on using addEventListener()... Does anyone know how i can change the above line in question to use addEventListener()?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.