Javascript滑鼠移入智能提示浮動層Tips效果

來源:互聯網
上載者:User
提示:您可以先修改部分代碼再運行

<!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" > <div class="adorn"></div> <div class="inner_html"></div> </div> <ul id="content"> <li>這是文字1111的, 也可以是圖片</li> <li>這是文字2222的, 也可以是圖片</li> <li>這是文字3333的, 也可以是圖片</li></ul> </body> </html> </td> </tr></table>
提示:您可以先修改部分代碼再運行

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.