var osy = element.offsetY;
There's no such property as offsetY
. You may be thinking of offsetTop
. However note the offsetLeft
/Top
values are relative to the offsetParent
not the page. If you want page-relative co-ordinates you would need to loop through offsetParents, or, since you seem to be including jQuery, call its offset function that does just that:
var offset= $(element).offset();
var osx= offset[0], osy= offset[1];
var bottom = osy + element.height();
element
is a DOM HTMLDivElement object, not a jQuery wrapper object, so it doesn't have the height()
method. Either add the wrapper:
var bottom= osy+$(element).height();
or use the equivalent DOM method:
var bottom= osy+element.offsetHeight;
var y = bottom - ev.pageY;
Note pageY
is not part of the DOM Events standard and also not available in IE. You can calculate it by using the standard clientY
property and adjusting for the page's scrollTop
. Again, jQuery does this for you, adding the Firefox pageY
extension to all browsers, when you use its own methods to bind your event handler:
$('#div1').mouseover(handleEvent);
instead of the inline onmouseover=...
event handler attribute.