JS实现的鼠标移入智能提示浮动层Tips

<!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> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>JS实现的鼠标移入智能提示层Tips</title> 
<style> 
* { padding: 0; margin: 0; } 
li { } 
body { background: #fdf7f7; } 

#explain { height: 60px; border-bottom: 1px solid #999999; background: #eee; font-size: 14px; color: #666; text-align: center; line-height: 60px; } 
#explain a { color: #990000; font-weight: bold; text-decoration: none; border-bottom: 1px dotted #990000; } 
#explain a:hover { border-bottom: 2px solid #990000; } 
#explain strong { color: #990000; } 
ul { width: 716px; position: absolute; top: 260px; left: 50%; margin-left: -358px; } 
li { width: 160px; height: 100px; list-style: none; background: #fff; padding: 3px; border-top: 1px solid #ddd; border-right: 2px solid #ddd; border-bottom: 2px solid #ddd; border-left: 1px solid #ddd; float: left; margin-right: 10px; cursor: pointer; } 
img { float: left; } 
#topic { width: 270px; background: #fff; padding: 3px; border-top: 1px solid #ddd; border-right: 2px solid #ddd; border-bottom: 2px solid #ddd; border-left: 1px solid #ddd; position: absolute; top: 100px; left: 200px; } 
#topic .adorn { width: 7px; height: 11px; overflow: hidden; background: url(/upload/201011/20101103150729602.gif); position: absolute; bottom: 15px; left: -7px; } 
#topic .adorn_r { width: 7px; height: 11px; overflow: hidden; background: url(/upload/201011/20101103150729137.gif); position: absolute; bottom: 15px; right: -7px; } 
#topic .inner_html { padding: 10px; line-height: 20px; font-size: 12px; color: #666; text-indent: 24px; font-family: arial; } 
#topic .inner_html a { color: #990000; font-weight: bold; text-decoration: none; border-bottom: 1px dotted #990000; } 
#topic .inner_html a:hover { border-bottom: 2px solid #990000; } 
</style> 
<script type="text/javascript"> 
var g_aData= 
'ok12.net---好用的鼠标提示符好用的鼠标提示符好用的鼠标提示符---1111',
'ok12.net---好用的鼠标提示符好用的鼠标提示符好用的鼠标提示符---2222', 
'ok12.net---好用的鼠标提示符好用的鼠标提示符好用的鼠标提示符---3333'
]; 

var g_oTimerHide=null; 

window.onload=function () 
var aLi=document.getElementById('content').getElementsByTagName('li'); 

bindTopic(aLi); 
}; 

function bindTopic(aElement) 
var i=0; 

for(i=0;i<aElement.length;i++) 
aElement[i].miaovIndex=i; 
aElement[i].onmouseover=function (ev){showTopic(this.miaovIndex, window.event || ev);}; 
aElement[i].onmouseout=function (){hideTopic();}; 
aElement[i].onmousemove=function (ev) 
var oEvent=window.event || ev; 
setPosition(oEvent.clientX, oEvent.clientY); 
}; 

function showTopic(index, oEvent) 
var oTopic=document.getElementById('topic'); 

if(g_oTimerHide) 
clearTimeout(g_oTimerHide); 

oTopic.getElementsByTagName('div')[1].innerHTML=g_aData[index]; 
oTopic.style.display='block'; 

setPosition(oEvent.clientX, oEvent.clientY); 

function hideTopic() 
var oTopic=document.getElementById('topic'); 

if(g_oTimerHide) 
clearTimeout(g_oTimerHide); 
g_oTimerHide=setTimeout 
function () 
oTopic.style.display='none'; 
},50 
); 

function setPosition(x, y) 
var top=document.body.scrollTop || document.documentElement.scrollTop; 
var left=document.body.scrollLeft || document.documentElement.scrollLeft; 

x+=left; 
y+=top; 

var oTopic=document.getElementById('topic'); 
var l=x+20; 
var t=y-(oTopic.offsetHeight-20); 
var bRight=true; 
var iPageRight=left+document.documentElement.clientWidth; 

if(l+oTopic.offsetWidth>iPageRight) 
bRight=false; 

l=x-(oTopic.offsetWidth+20); 
oTopic.getElementsByTagName('div')[0].className='adorn_r'; 
else 
oTopic.getElementsByTagName('div')[0].className='adorn'; 

oTopic.style.left=l+'px'; 
oTopic.style.top=t+'px'; 
</script> 
</head> 

<body> 
<div id="explain">可以调整窗口大小,再把鼠标移到图片上查看……</div> 
<div id="topic" style="display: none; z-index:2"> 
<div class="adorn"></div> 
<div class="inner_html"></div> 
</div> 

<ul id="content"> 
<li>这是文字1111的, 也可以是图片<img /></li> 
<li>这是文字2222的, 也可以是图片<img /></li> 
<li>这是文字3333的, 也可以是图片<img /></li>
</ul> 
</body> 
</html> 

本博客所有文章如无特别注明均为原创。作者:sysdee复制或转载请以超链接形式注明转自 成功志
原文地址《JS实现的鼠标移入智能提示浮动层Tips
分享到:更多

相关推荐

发表评论

路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交

网友评论(0)