相思资源网 Design By www.200059.com
复制代码 代码如下:
//获取元素的位置
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;
};
//获取鼠标的位置
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;
标签:
元素位置,鼠标位置

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“多浏览器兼容的获取元素和鼠标的位置的js代码”

暂无多浏览器兼容的获取元素和鼠标的位置的js代码的评论...