RSS
热门关键字:  虚拟主机技术  vps团购  discuz架构  虚拟主机团购  curl

鼠标滑过出现提示层效果js代码 javascript

来源: 作者: 时间:2008-11-06 Tag: 点击:

演示

源码source code:

  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. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title>鼠标滑过出现提示层效果 js代码 javascript</title>
  6. <script type="text/javascript">
  7. function enableTooltips(id){
  8. var links,i,h;
  9. if(!document.getElementById || !document.getElementsByTagName) return;
  10. AddCss();
  11. h=document.createElement("span");
  12. h.id="btc";
  13. h.setAttribute("id","btc");
  14. h.style.position="absolute";
  15. document.getElementsByTagName("body")[0].appendChild(h);
  16. if(id==null) links=document.getElementsByTagName("a");
  17. else links=document.getElementById(id).getElementsByTagName("a");
  18. for(i=0;i<links.length;i++){
  19. Prepare(links[i]);
  20. }
  21. }function Prepare(el){
  22. var tooltip,t,b,s,l;
  23. t=el.getAttribute("title");
  24. if(t==null || t.length==0) t="link:";
  25. el.removeAttribute("title");
  26. tooltip=CreateEl("span","tooltip");
  27. s=CreateEl("span","top");
  28. s.appendChild(document.createTextNode(t));
  29. tooltip.appendChild(s);
  30. b=CreateEl("b","bottom");
  31. l=el.getAttribute("href");
  32. if(l.length>30) ll=l.substr(0,27)+"...";
  33. b.appendChild(document.createTextNode(l));
  34. tooltip.appendChild(b);
  35. setOpacity(tooltip);
  36. el.tooltip=tooltip;
  37. el.onmouseover=showTooltip;
  38. el.onmouseout=hideTooltip;
  39. el.onmousemove=Locate;
  40. }function showTooltip(e){
  41. document.getElementById("btc").appendChild(this.tooltip);
  42. Locate(e);
  43. }function hideTooltip(e){
  44. var d=document.getElementById("btc");
  45. if(d.childNodes.length>0) d.removeChild(d.firstChild);
  46. }function setOpacity(el){
  47. el.style.filter="alpha(opacity:95)";
  48. el.style.KHTMLOpacity="0.95";
  49. el.style.MozOpacity="0.95";
  50. el.style.opacity="0.95";
  51. }function CreateEl(t,c){
  52. var x=document.createElement(t);
  53. x.className=c;
  54. x.style.display="block";
  55. return(x);
  56. }function AddCss(){
  57. var l=CreateEl("link");
  58. l.setAttribute("type","text/css");
  59. l.setAttribute("rel","stylesheet");
  60. l.setAttribute("href","?.css");
  61. l.setAttribute("media","screen");
  62. document.getElementsByTagName("head")[0].appendChild(l);
  63. }function Locate(e){
  64. var posx=0,posy=0;
  65. if(e==null) e=window.event;
  66. if(e.pageX || e.pageY){
  67. posx=e.pageX; posy=e.pageY;
  68. }
  69. else if(e.clientX || e.clientY){
  70. if(document.documentElement.scrollTop){
  71. posx=e.clientX+document.documentElement.scrollLeft;
  72. posy=e.clientY+document.documentElement.scrollTop;
  73. }
  74. else{
  75. posx=e.clientX+document.body.scrollLeft;
  76. posy=e.clientY+document.body.scrollTop;
  77. }
  78. }
  79. document.getElementById("btc").style.top=(posy+10)+"px";
  80. document.getElementById("btc").style.left=(posx-20)+"px";
  81. }
  82. </script>
  83. <script type="text/javascript">
  84. window.onload=function(){enableTooltips()};
  85. </script>
  86. <style type="text/css">
  87. body{font: 76%/1.5 Arial,sans-serif;background: #FFF;color: #333}
  88. div#container{width: 500px;margin:0 auto}
  89. h1{color: #3CA3FF;margin: 1em 0 0;letter-spacing: -2px}
  90. p{margin: 0 0 1.7em}
  91. a{color: #F60;font-weight:bold}
  92. a:hover{color: #F00}
  93. .tooltip{
  94. width: 200px; color:#000;
  95. font:lighter 11px/1.3 Arial,sans-serif;
  96. text-decoration:none;text-align:center}.tooltip span.top{padding: 30px 8px 0;
  97.      background: url(http://www.51flash.cn/wp-content/uploads/2007/0908/200708171844190.gif) no-repeat top}.tooltip b.bottom{padding:3px 8px 15px;color: #548912;
  98.      background: url(http://www.51flash.cn/wp-content/uploads/2007/0908/200708171844190.gif) no-repeat bottom}
  99. </style>
  100. </head>
  101. <body>
  102. <div id="container">
  103. <p><a href="http://www.51flash.cn" title="welcome to you">51flash.cn</a></p>
  104. </div>
  105. </body>
  106. </html>

 


    由于各种原因,我们无法获知[鼠标滑过出现提示层效果js代码 javascript]原创作者,如侵犯了您的版权,请您及时联系我们!
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册