Find the position of an event (mouse over on a button), for Firefox extension
I need to find the position of an event (mouse over on a button), for Firefox extension. I have been using:
var obj = $mb(e.target,doc).offset();
var left = obj.left;
var top = obj.top;
But the problem is the value returned by it is the position of an event in the screen not of the page,that is it doesn't take scroll position into consideration {in Firefox} ..(but in Google Chrome its working).
Then I used mouse position.
var obj_left = (window.Event) ? e.pageX : ev开发者_JAVA百科ent.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
But the problem is it returns different values according to the mouse position that cause event (different values for same button at the two ends of button), but in the first case even though it returns screen position it returns a single value for the event (a single value for a button at the two ends).
What I need is return value should be same for event and should take scroll position into account.
Mouse events in Firefox have both a pageX
and a clientX
property (see documentation at https://developer.mozilla.org/en/DOM/event.pageX and https://developer.mozilla.org/en/DOM/event.clientX respectively). It seems that pageX
is what you want - position relative to the current page, regardless of scrolling. pageX
is non-standard and probably not implemented in Chrome but jQuery seems to provide this property in a cross-browser fashion, see http://api.jquery.com/event.pageX/.
精彩评论