87,910
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<style type="text/css">
#oTip{
width: 120px;
height: 140px;
border: 2px solid #3366FF;
background-color: #FFFEE8;
text-align: center;
display: none;
position: absolute;
font-size: 9pt;
}
#oTip li{
line-height: 20px;
}
</style>
<script type="text/javascript">
<!--
// 添加事件
var addEvent = function(a, b, c, d){
if(a.attachEvent) a.attachEvent(b[0], c);
else a.addEventListener(b[1] || b[0].replace(/^on/,""), c, d || false);
return c;
}
// 取得元素位置
var getPosition = function(el){
var itop = el.offsetTop;
var ileft = el.offsetLeft;
while(el = el.offsetParent){
itop += el.offsetTop;
ileft += el.offsetLeft;
}
return {y: itop, x: ileft};
}
// 加载时绑定mouseover mouseout事件
window.onload = function(){
var oDiv = document.getElementById("oDiv");
addEvent(oDiv, ["onmouseover"], function(e){
showTips(e)
});
addEvent(oDiv, ["onmouseout"], function(e){
disTips(e)
});
}
// 显示Tips
function showTips(e){
var e = e || window.event;
var otarget = e.srcElement || e.target;
var oTip = document.getElementById("oTip");
oTip.style.display = "block";
oTip.style.position = "absolute";
oTip.style.top = (getPosition(otarget).y + 36) + "px";
oTip.style.left = getPosition(otarget).x + "px";
}
// 隐藏Tips
function disTips(e){
var e = e || window.event;
var otarget = e.srcElement || e.target;
var oTip = document.getElementById("oTip");
oTip.style.display = "none";
}
//-->
</script>
</head>
<body>
<div id="oDiv" style="width:40px;height:20px;background-Color:#009900;font-size:9pt;">showTips</div>
<div id="oTip" >
<ul>
<li><a href="http://www.baidu.com"> www.baidu.com </a></li>
<li><a href="http://www.google.com"> www.google.com </a></li>
<li><a href="http://www.sina.com"> www.sina.com </a></li>
<li><a href="http://www.163.com"> www.163.com </a></li>
</ul>
</div>
</body>
</html>
var oTipTimer;
// 加载时绑定mouseover mouseout事件
window.onload = function(){
var oDiv = document.getElementById("oDiv");
addEvent(oDiv, ["onmouseover"], function(e){
clearTimeout(oTipTimer);
showTips(e);
});
addEvent(oDiv, ["onmouseout"], function(e){
oTipTimer = setTimeout(function(){
disTips(e);
}, 1000);
});
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<style type="text/css">
#oTip{
width: 120px;
height: 140px;
border: 2px solid #3366FF;
background-color: #FFFEE8;
text-align: center;
display: none;
position: absolute;
font-size: 9pt;
}
#oTip li{
line-height: 20px;
}
</style>
<script type="text/javascript">
<!--
// 添加事件
var addEvent = function(a, b, c, d){
if(a.attachEvent) a.attachEvent(b[0], c);
else a.addEventListener(b[1] || b[0].replace(/^on/,""), c, d || false);
return c;
}
// 取得元素位置
var getPosition = function(el){
var itop = el.offsetTop;
var ileft = el.offsetLeft;
while(el = el.offsetParent){
itop += el.offsetTop;
ileft += el.offsetLeft;
}
return {y: itop, x: ileft};
}
// 加载时绑定mouseover mouseout事件
window.onload = function(){
var oDiv = document.getElementById("oDiv");
var oTip = document.getElementById("oTip");
addEvent(oDiv, ["onmouseover"], function(e){
showTips(e)
});
addEvent(oDiv, ["onmouseout"], function(e){
disTips(e)
});
addEvent(oTip, ["onmouseout"], function(e){
disTips(e)
});
}
// 显示Tips
function showTips(e){
var e = e || window.event;
var otarget = e.srcElement || e.target;
var oTip = document.getElementById("oTip");
oTip.style.display = "block";
oTip.style.position = "absolute";
oTip.style.top = (getPosition(otarget).y + otarget.offsetHeight) + "px";
oTip.style.left = getPosition(otarget).x + "px";
}
// 隐藏Tips
function disTips(e){
var e = e || window.event;
var otarget = e.relatedTarget||e.toElement;
var oTip = document.getElementById("oTip");
if(judge(oTip,otarget))return
oTip.style.display = "none";
}
function judge(parent,child){
if(parent == child) return true;
while(child=child.parentNode){if(child==parent)return true;}
return false;
}
//-->
</script>
</head>
<body>
<div id="oDiv" style="width:40px;height:20px;background-Color:#009900;font-size:9pt;">showTips</div>
<div id="oTip" >
<ul>
<li><a href="http://www.baidu.com"> www.baidu.com </a></li>
<li><a href="http://www.google.com"> www.google.com </a></li>
<li><a href="http://www.sina.com"> www.sina.com </a></li>
<li><a href="http://www.163.com"> www.163.com </a></li>
</ul>
</div>
</body>
</html>