標籤:jquery ui web前端 前端 架構
覺得純css的tips限制有點大,而且好像相容性也不好,這是我發現的一個Js+CSS的連結提示框效果,還會跟隨滑鼠而移動,而且相容性也不錯,代碼與大家分享:前端分享
.代碼
- <!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>跟隨滑鼠的文字提示框</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <style type="text/css">
- body{font:12px/1.8 arial;}
- a,a:visited{color:#3366cc;text-decoration:none;}
- a:hover{color:#f60;text-decoration:underline;}
- .tip{width:200px;border:2px solid #ddd;padding:8px;background:#f1f1f1;color:#666;}
- img{border:none;}
- </style>
- <script type="text/javascript">
- var tip={$:function(ele){
- if(typeof(ele)=="object")
- return ele;
- else if(typeof(ele)=="string"||typeof(ele)=="number")
- return document.getElementById(ele.toString());
- return null;
- },
- mousePos:function(e){
- var x,y;
- var e = e||window.event;
- return{x:e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,
- y:e.clientY+document.body.scrollTop+document.documentElement.scrollTop};
- },
- start:function(obj){
- var self = this;
- var t = self.$("mjs:tip");
- obj.onmousemove=function(e){
- var mouse = self.mousePos(e);
- t.style.left = mouse.x + 10 + ‘px‘;
- t.style.top = mouse.y + 10 + ‘px‘;
- t.innerHTML = obj.getAttribute("tips");
- t.style.display = ‘‘;
- };
- obj.onmouseout=function(){
- t.style.display = ‘none‘;
- };
- }
- }
- </script>
- </head>
- <body>
- <ol>
- <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>
- <li><a href="#" target="_blank" onmouseover="tip.start(this)" tips="中國未來一定是世界上最強大的國家,你相信嗎?">中國是世界上最強大的國家</a></li>
- </ol>
- <div id="mjs:tip" class="tip" style="position:absolute;left:0;top:0;display:none;"></div>
- </body>
- </html>
也就是為每一個a標籤添加一個tips標籤,用JS控制顯示的,所以在你的頁面添加本連結提示前,請複製代碼內的JavaScript代碼到你的頁面中,然後為需要提示的連結添加Tips標籤。前端架構分享