bob体育官方平台
【bob体育app】多浏览器包容的拿走成分和鼠标的地方的js代码_javascript技艺_脚本之家

复制代码 代码如下://获取元素的位置 function getLeft { if 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 { if 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 { var position = { MouseX: 0, MouseY: 0 } if (event.pageX != undefined) { position.MouseX = event.pageX; position.MouseY = event.pageY; } else { var target = EventUtil.getTarget; position.MouseX = event.offsetX + getLeft; position.MouseY = event.offsetY + getTop; } return position;

在需要实现功能的地方绑定实现 onmouseover="ShowPrompt(this)" onmouseout="HiddenPrompt()" 一个用于弹出层,一个用于隐藏层

编辑一个div用作层,以便显示内容

这里是层显示的内容

js事件代码,用来触发层的显示和隐藏

//传入 event 对象,获得元素的坐标以便更好的设置弹出层的位置

function ShowPrompt(objEvent) {

var divObj = document.getElementById("promptDiv");

divObj.style.visibility = "visible";

divObj.style.left = getLeft(objEvent) + 0 + 'px';

divObj.style.top = getTop(objEvent) + 30 + 'px';

}

//隐藏提示框

function HiddenPrompt() {

divObj = document.getElementById("promptDiv");

返回顶部