日期:2014-05-16 浏览次数:20388 次
var docElem, win,
box = { top: 0, left: 0 },
elem = this[ 0 ],
doc = elem && elem.ownerDocument;
if ( !doc ) {
return;
}
docElem = doc.documentElement;
// Make sure it's not a disconnected DOM node
if ( !jQuery.contains( docElem, elem ) ) {
return box;
}
// If we don't have gBCR, just use 0,0 rather than error
// BlackBerry 5, iOS 3 (original iPhone)
if ( typeof elem.getBoundingClientRect !== core_strundefined ) {
box = elem.getBoundingClientRect();
}
win = getWindow( doc );
return {
top: box.top + ( win.pageYOffset
------解决方案--------------------
docElem.scrollTop ) - ( docElem.clientTop
------解决方案--------------------
0 ),
left: box.left + ( win.pageXOffset
------解决方案--------------------
docElem.scrollLeft ) - ( docElem.clientLeft
------解决方案--------------------
0 )
};
$(function() {
$("#p1").click(function(e) {
//offset()获得的是元素的左上角相对于整个网页的坐标
var offset = $("#p1").offset();
$("#MsgShow").append("offset.top:" + $(e.target).offset().top + " offset.left:" + $(e.target).offset().left + " e.pageX:" + e.pageX + " e.pageY:" + e.pageY + "<br/>");