欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

多瀏覽器兼容的獲取元素和鼠標(biāo)的位置的js代碼

 更新時間:2009年12月15日 17:45:34   作者:  
獲取元素和鼠標(biāo)的位置(兼容IE6.0,IE7.0,IE8.0,FireFox2.0,FireFox3.5,Opera),該功能是我一同事鉆研出來的,目標(biāo)是為了實現(xiàn)與QQ自定義布局和拖放模塊類似的功能。
復(fù)制代碼 代碼如下:

//獲取元素的位置
function getLeft(obj) {
if (obj == null)
return null;
var mendingObj = obj;
var mendingLeft = mendingObj.offsetLeft;
while (mendingObj != null && mendingObj.offsetParent != null && mendingObj.offsetParent.tagName != "BODY") {
mendingLeft = mendingLeft + mendingObj.offsetParent.offsetLeft;
mendingObj = mendingObj.offsetParent;
}

return mendingLeft;
};
function getTop(obj) {
if (obj == null)
return null;
var mendingObj = obj;
var mendingTop = mendingObj.offsetTop;
while (mendingObj != null && mendingObj.offsetParent != null && mendingObj.offsetParent.tagName != "BODY") {
mendingTop = mendingTop + mendingObj.offsetParent.offsetTop;
mendingObj = mendingObj.offsetParent;
}
return mendingTop;
};
//獲取鼠標(biāo)的位置
function getMousePosition(event) {
var position = {
MouseX: 0,
MouseY: 0
}
if (event.pageX != undefined) {
position.MouseX = event.pageX;
position.MouseY = event.pageY;
}
else {
var target = EventUtil.getTarget(event);
position.MouseX = event.offsetX + getLeft(target);
position.MouseY = event.offsetY + getTop(target);

}
return position;

相關(guān)文章

最新評論