日期:2014-05-16 浏览次数:20498 次
?
document.getElementById('msgdiv').style.left=getPosLeft(a)+25;
?? document.getElementById('msgdiv').style.top=getPosTop(a)+15
?
a为要取到坐标的对象
?
function getPosLeft(obj)
{
??? var l = obj.offsetLeft;
??? while(obj = obj.offsetParent)
??? {
??????? l += obj.offsetLeft;
??? }
??? return l;
}
?
?
function getPosTop(obj)
{
??? var l = obj.offsetTop;
??? while(obj = obj.offsetParent)
??? {
??????? l += obj.offsetTop;
??? }
??? return l;
}