61,115
社区成员
发帖
与我相关
我的任务
分享
<style type="text/css">
body{ margin:0; padding;}
.tip{ position:absolute; height:100px; width:100px; border:1px solid #000; background:#fff; padding:5px}
</style>
<br />
<br />
<br />
<br />
<br />
<a href="#" id="a" style="width:50px; height:30px; border:1px solid red; display:block">点击</a>
<script type="text/javascript">
var a = document.getElementById("a")
var tip;
a.onmouseover = function ()
{
tip = document.createElement("div");
tip.className = "tip";
tip.style.top=this.offsetTop+"px";
tip.style.left = this.offsetLeft+this.offsetWidth-1+"px"
tip.innerHTML = "<span>内容</span>"
document.body.appendChild(tip);
tip.onmouseout = function(e)
{
var to = e ? e.relatedTarget : window.event.toElement;
if(this.contains)
{
if(this.contains(to)) return false;
}
else
{
while(to)
{
if(to == this) return;
to = to.parentNode;
}
}
document.body.removeChild(tip);
tip = null;
}
}
a.onmouseout = function(e)
{
var to = e ? e.relatedTarget : window.event.toElement;
if(to == tip) return;
if(tip)
{
document.body.removeChild(tip);
tip = null
}
}
</script>