/ Published in: JavaScript

Just a short and simple way of finding the mouse position.
Expand |
Embed | Plain Text
mousePosition = function(){ var e = e||window.event; return {x:e.clientX,y:e.clientY} } // Called in the following way: mousePosition().x //or mousePosition().y //If you want to take into account the scroll position you can also do the following: mousePosition = function(){ var e = e||window.event,dp = document.body.parentElement,ofy = window.pageYOffset, ofx = window.pageXOffset; return {x:e.clientX+parseInt(ofx?ofx:dp.scrollLeft),y:e.clientY+parseInt(ofy?ofy:dp.scrollTop)} }
You need to login to post a comment.