日期:2014-05-18  浏览次数:20518 次

鼠标经过悬浮层的坐标问题,急!在线等
<script language="javascript">
  function Show(id,num) {
  document.getElementById("td1").innerText = "ID:" + id;
  document.getElementById("td2").innerText = "编号: " + num;
  //x = event.clientX + document.body.scollRight;
  //y = event.clientY + document.body.scrollBottom + 80;
  x = event.screenX;
  y = event.screenY;
  div1.style.display = "block";
  div1.style.left = x;
  div1.style.top = y;
  }
这是鼠标经过时,悬浮层的显示函数,这个悬浮层的坐标要怎样设置,才能使其紧挨鼠标位于鼠标的下方呢,这段代码只能是它位于屏幕的左上方,求大神帮忙啊,在线等!

------解决方案--------------------
var tip = { $: function (ele) {
if (typeof (ele) == "object")
return ele;
else if (typeof (ele) == "string" || typeof (ele) == "number")
return document.getElementById(ele.toString());
return null;
},
//获取鼠标坐标
mousePos: function (e) {
var x, y;
var e = e || window.event;
return {
//鼠标相对于当前窗口的x坐标
x: e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
//鼠标相对于当前窗口的y坐标
y: e.clientY + document.body.scrollTop + document.documentElement.scrollTop
};
},
function Show(id,num) {
document.getElementById("td1").innerText = "ID:" + id;
document.getElementById("td2").innerText = "编号: " + num;
var self = this;
var t = self.$("div1");
//鼠标在控件上移动时触发的悬浮框的弹出事件
obj.onmousemove = function (e) {
var mouse = self.mousePos(e);
t.style.display = '';
t.style.left = mouse.x + 'px'; //悬浮框的左边界相对于当前窗口的左端的距离
t.style.top = mouse.y + 'px'; //悬浮框的上边界相对于当前窗口的顶端的距离
}
}
}