87,917
社区成员
发帖
与我相关
我的任务
分享
直接给当前图片添加onmouseover、onmouseout事件,事件不要搞错了
首先移到图片上显示div,主要div要和img连接起来。不要隔得距离太大
这样当鼠标移到图片外面去的时候,还来不及点div就隐藏了
在div、img添加鼠标离开的事件,离开隐藏
<div onmousemove="Description(this,'<div style=color:red;>hiadfasdfasdfasdfsdf</div>')">
adfasdfasdf</div>
function Description(o, strHtml) {
var obj = document.getElementById(o + "_temp");
if (!obj) {
var a = document.createElement("div");
with (a.style) {
background = '#f3f3f3';
border = '1px solid #ccc';
fontSize = '12px';
position = 'absolute';
lineHeight = "22px";
left = loc(o, "Left") + 60 + "px";
top = loc(o, "Top") + o.offsetHeight - 22 + "px";
padding = "1px";
width = 'auto';
height = 'auto';
overflow = 'hidden';
display = "block";
}
a.id = o + '_temp';
document.body.appendChild(a);
a.innerHTML = strHtml;
}
else {
obj.style.display = "block";
obj.innerHTML = strHtml;
}
o.onmouseout = function(e) { clear(e, o + "_temp"); }
}
function loc(o, sProp) {
var i = 0;
while (o) {
i += o["offset" + sProp];
if (o.offsetParent) { if (o.offsetParent.style.position == "absolute") return i; }
o = o.offsetParent;
} return i;
}
function clear(e, popid) { e = window.event || e; var s = e.relatedTarget || e.toElement; var pop = document.getElementById
(popid); if (pop && s) { pop.style.display = (pop == s || s == pop.parentNode || s == s.parentNode) ? "block" : "none";
pop.onmouseover = function(e) { this.style.display = "block"; }; pop.onmouseout = function(e) { this.style.display = "none";
}; } }