Jump to content

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()?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.