freelance84 Posted July 27, 2011 Share Posted July 27, 2011 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()? Quote Link to comment https://forums.phpfreaks.com/topic/242932-addeventlistener-as-captureevents-deprecated/ Share on other sites More sharing options...
nogray Posted July 28, 2011 Share Posted July 28, 2011 Just remove the line in question and everything should work. Quote Link to comment https://forums.phpfreaks.com/topic/242932-addeventlistener-as-captureevents-deprecated/#findComment-1248758 Share on other sites More sharing options...
freelance84 Posted July 29, 2011 Author Share Posted July 29, 2011 Hmm... well, that makes sense! Thanks a lot! Seemed to easy to be correct but it worked! Quote Link to comment https://forums.phpfreaks.com/topic/242932-addeventlistener-as-captureevents-deprecated/#findComment-1248929 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.