var pos=GetObjPos(ID);
function CPos(x, y)
{
this.x = x;
this.y = y;
}
//获取控件的位置
function GetObjPos(ATarget)
{
var target = ATarget;
var pos = new CPos(target.offsetLeft, target.offsetTop);
var target = target.offsetParent;
while (target)
{
pos.x += target.offsetLeft;
pos.y += target.offsetTop;
target = target.offsetParent
}
return pos;
}
下面是我自己开发项目中的实例:
复制代码 代码如下:
<script type="text/jscript" language="jscript" >
function showPopup(obj,evt) {
var strDate = $(obj).attr('dateTime');
var strUserName = $(obj).attr('userName');
var id = "event_" + strDate.replace(/-/g, '');
var box = $('#'+id);
if (box.length == 0) {
$(document.body).append("<div></div>");
box = $('#' + id);
box.css("position", "absolute");
box.css("display", "block");
box.css("z-index", "100");
box.append('<input type="image" src="https://www.jb51.net/Images/Onload.gif"/>');
Microsoft.PMWeb.WebSite.SiteService.GetEventInfoByDate(strUserName + "#" + strDate, onSuccess, onFailed, "1111");
}
else {
var imgLoad = box.find(":image");
imgLoad.css("display", "none");
}
var objQueryPosition = GetObjPos(obj);
box.css("left", mousePos.x);
box.css("top", mousePos.y);
box.css("display", "");
function onSuccess(result, context, methodName) {
var imgLoad = box.find(":image");
imgLoad.css("display","none");
box.append(result);
}
function onFailed(error, context, methodName) {
var errorMessage = error.get_message();
alert("Review Failed:" + errorMessage);
}
}
function hidePopup(obj) {
var strDate = $(obj).attr('dateTime');
var strUserName = $(obj).attr('userName');
var id = "event_" + strDate.replace(/-/g, '');
var box = $('#'+id);
if (box.length != 0) {
$('#'+id).css("display", "none");
}
}
var mousePos;
function mouseMove(ev) {
ev = ev || window.event;
mousePos = mouseCoords(ev);
}
function mouseCoords(ev) {
if (ev.pageX || ev.pageY) {
return { x: ev.pageX, y: ev.pageY };
}
return {
x: ev.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft),
y: ev.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop)
};
}
document.onmousemove = mouseMove;
</script>
您可能感兴趣的文章: