支援滑鼠跟隨的JS+CSS連結提示框

來源:互聯網
上載者:User

標籤:jquery   ui   web前端   前端   架構   

覺得純css的tips限制有點大,而且好像相容性也不好,這是我發現的一個Js+CSS的連結提示框效果,還會跟隨滑鼠而移動,而且相容性也不錯,代碼與大家分享:前端分享

.代碼  
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <title>跟隨滑鼠的文字提示框</title>  
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  6. <style type="text/css">  
  7. body{font:12px/1.8 arial;}  
  8. a,a:visited{color:#3366cc;text-decoration:none;}  
  9. a:hover{color:#f60;text-decoration:underline;}  
  10. .tip{width:200px;border:2px solid #ddd;padding:8px;background:#f1f1f1;color:#666;}  
  11. img{border:none;}  
  12. </style>  
  13. <script type="text/javascript">  
  14.   var tip={$:function(ele){  
  15.   if(typeof(ele)=="object")  
  16.     return ele;  
  17.   else if(typeof(ele)=="string"||typeof(ele)=="number")  
  18.     return document.getElementById(ele.toString());  
  19.     return null;  
  20.   },  
  21.   mousePos:function(e){  
  22.     var x,y;  
  23.     var e = e||window.event;  
  24.     return{x:e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,  
  25. y:e.clientY+document.body.scrollTop+document.documentElement.scrollTop};  
  26.   },  
  27.   start:function(obj){  
  28.     var self = this;  
  29.     var t = self.$("mjs:tip");  
  30.     obj.onmousemove=function(e){  
  31.       var mouse = self.mousePos(e);  
  32.       t.style.left = mouse.x + 10 + ‘px‘;  
  33.       t.style.top = mouse.y + 10 + ‘px‘;  
  34.       t.innerHTML = obj.getAttribute("tips");  
  35.       t.style.display = ‘‘;  
  36.     };  
  37.     obj.onmouseout=function(){  
  38.       t.style.display = ‘none‘;  
  39.     };  
  40.   }  
  41.   }  
  42. </script>  
  43. </head>  
  44. <body>  
  45. <ol>  
  46. <li><a href="#" target="_blank" onmouseover="tip.start(this)" tips="2013年12月14日,ECS Operations and Maintenance System3號衛星登上月球,激動人心的一切終於到來了……">中國ECS Operations and Maintenance System飛天的一些感想</a></li>  
  47. <li><a href="#" target="_blank" onmouseover="tip.start(this)" tips="中國未來一定是世界上最強大的國家,你相信嗎?">中國是世界上最強大的國家</a></li>  
  48. </ol>  
  49. <div id="mjs:tip" class="tip" style="position:absolute;left:0;top:0;display:none;"></div>  
  50. </body>  
  51. </html>  

 

也就是為每一個a標籤添加一個tips標籤,用JS控制顯示的,所以在你的頁面添加本連結提示前,請複製代碼內的JavaScript代碼到你的頁面中,然後為需要提示的連結添加Tips標籤。前端架構分享

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.