您的位置主页 > 前端技术 > Html+Css > 自定义title样式 同时支持firefox ie

自定义title样式 同时支持firefox ie

2009-11-11    文章来源:互联网    浏览次数:1331     分享文章

第一种方法:

 
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  4. <title>自定义title - azhong.com</title>
  5. </head>
  6. <body >
  7. <p><B>自定义title</B>(IE & FireFox...):把鼠标放在下面的文字上查看效果</p>
  8. <span title="Javascript" title="">默认效果</span><br><br>
  9. <span title="<marquee style='width:60px;'>www.azhong.com</marquee>" altbg="red" altcolor="yellow" altborder="yellow">滚动字幕</span><br><br>
  10. <span title="<img src='http://www.azhong.com/azhong.com.logo.gif' border='0'>" altbg="#F7F7F7" altcolor="#999999" altborder="#CCCCCC">图片</span><br><br>
  11. <span title="<i style='font-size:18pt;font-family:verdana;'>welcome to <font color='yellow'>www.azhong.com</font></i>" altbg="green" altcolor="black" altborder="darkgreen">大字体大字体大字体大字体大字体大字体大字体大字体大字体大字体大字体大字体大字体大字体大字体大字体大字体大字体大字体</span><br><br>
  12. <div style="display:none;border:1px solid #000000;background-color:#FFFFCC;font-size:12px;position:absolute;padding:2;" id="_altlayer"></div>
  13. <SCRIPT LANGUAGE="JavaScript">
  14. <!--
  15. document.body.onmousemove=quickalt;
  16. document.body.onmouseover=getalt;
  17. document.body.onmouseout=restorealt;
  18. var tempalt='';
  19.  
  20. var UA=navigator.userAgent.toLowerCase();
  21. var ISIE=(UA.indexOf("msie") > 0);
  22. function $(hw_){return document.getElementById(hw_);}
  23.  
  24. function _Move(evn,o){
  25.     _bW=document.body.clientWidth;
  26.     _left1=document.body.scrollLeft+evn.clientX+10;
  27.     _oW=o.offsetWidth;
  28.     _left=((evn.clientX+_oW)>_bW)?(_left1-_oW-10):_left1;
  29.     if((evn.clientX+_oW)>_bW){_left=(_oW<evn.clientX)?(_left1-_oW-10):_left1;}
  30.  
  31.     _bH=document.body.clientHeight;
  32.     _top1=document.body.scrollTop+evn.clientY+6;
  33.     _oH=o.offsetHeight;
  34.     _top=((evn.clientY+_oH)>_bH)?(_top1-_oH-6):_top1;
  35.     if((evn.clientY+_oH)>_bH){_top1=(_oH<evn.clientY)?(_top1-_oH-6):_top1;}
  36.     o.style.left=_left;
  37.     o.style.top=_top;
  38. }
  39.  
  40. function getalt(hw_){
  41.     if(ISIE){evn=event}else{evn=hw_}
  42.     var eo = evn.srcElement?evn.srcElement:evn.target;
  43.     if(eo.title && (eo.title!=""|| (eo.title=="" && tempalt!=""))){
  44.         o = $("_altlayer");
  45.         _Move(evn,o);
  46.         o.style.display='';
  47.         tempalt=eo.title;
  48.         tempbg=eo.getAttribute("altbg");
  49.         tempcolor=eo.getAttribute("altcolor");
  50.         tempborder=eo.getAttribute("altborder");
  51.         eo.title='';
  52.         o.innerHTML=tempalt;
  53.         if (tempbg!=null){o.style.background=tempbg}else{o.style.background="infobackground"}
  54.         if (tempcolor!=null){o.style.color=tempcolor}else{o.style.color=tempcolor="infotext"}
  55.         if (tempborder!=null){o.style.border="1px solid "+tempborder;}else{o.style.border="1px solid #000000";}
  56.     }
  57. }
  58. function quickalt(hw_){
  59.     if(ISIE){evn=event}else{evn=hw_}
  60.     o = $("_altlayer");
  61.     if(o.style.display==""){
  62.         _Move(evn,o);
  63.     }
  64. }
  65. function restorealt(hw_){
  66.     if(ISIE){evn=event}else{evn=hw_}
  67.     var eo = evn.srcElement?evn.srcElement:evn.target;
  68.     eo.title=tempalt;
  69.     tempalt="";
  70.     $("_altlayer").style.display="none";
  71. }
  72. //-->
  73. </SCRIPT>
  74.  
  75. </body>
  76. </html>
  77.  

--------------------------------------------------------------------

第二种方法:

 
  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>根据鼠标的位置显示自定义提示-来自www.idcsrv.cn</title>
  6. <script language='javascript' type="text/javascript">
  7. function showdiv(objstr,str,ev)
  8. {//根据鼠标位置显示对象,参数ev为event
  9. var ObjX,ObjY;//对象的位置(x,y)
  10. var mouseX=10;//对象的(x)水平位置距离鼠标的宽度
  11. var mouseY=-2;//对象的(y)垂直位置距离鼠标的高度
  12. var obj = document.getElementById(objstr);
  13. obj.style.display=str;//显示或隐藏对象
  14. if(str == "")
  15. {    
  16. if(ev.pageX || ev.pageY)
  17. {//firefox鼠标的位置
  18.    ObjX = ev.pageX;
  19.    ObjY = ev.pageY;
  20. }
  21. else
  22. {//IE鼠标的位置  
  23.  
  24. //以下两行为旧标准支持
  25.    //ObjX = ev.clientX + document.body.scrollLeft- document.body.clientLeft;
  26.    //ObjY = ev.clientY + ddocument.body.scrollTop - document.body.clientTop;    
  27. //以下两行为新标准支持
  28.    ObjX = ev.clientX + document.documentElement.scrollLeft- document.body.clientLeft;
  29.    ObjY = ev.clientY + document.documentElement.scrollTop - document.body.clientTop;
  30. }
  31. ObjX = ObjX + mouseX;
  32. ObjY = ObjY - mouseY;
  33. obj.style.left = ObjX + 'px';
  34. obj.style.top = ObjY + 'px';   
  35. }
  36. }
  37. </script>
  38. <style type="text/css">
  39. .div1{
  40. position:absolute;
  41. border:1px #DFDFDF solid;
  42. background-color:#FFFFFF;
  43. line-height:180%;
  44. width:100px;
  45. font-size:12px;
  46. padding:3px;
  47. z-index:10001;
  48. filter:alpha(opacity=90);/*设置透明度*/
  49. -moz-opacity:0.9;/*Firefox设置透明度*/
  50. }
  51. * {font-size:12px;}
  52. .div1 p{margin:0px;}
  53. ul{margin:0px; padding:0px;}
  54. li{margin:0px; padding:0 0 0 2px; height:25px; display:inline}
  55. </style> 
  56. </head>
  57. <body>
  58. <ul>
  59. <li><a href="#" onmousemove="showdiv('divalt1','',event)" onmouseover="showdiv('divalt1','',event)" onmouseout="showdiv('divalt1','none')">显示div1显示div1显示div1</a></li>
  60. <div id="divalt1" class="div1" style="display:none">显示div1<br />显示div1<br />显示div1<br />显示div1</div>
  61. <li><a href="#" onmousemove="showdiv('divalt2','',event)" onmouseover="showdiv('divalt2','',event)" onmouseout="showdiv('divalt2','none')">显示div2显示div2显示div2</a></li>
  62. <div id="divalt2" class="div1" style="display:none">显示div2<br />显示div2<br />显示div2</div>
  63. <li><a href="#" onmousemove="showdiv('divalt3','',event)" onmouseover="showdiv('divalt3','',event)" onmouseout="showdiv('divalt3','none')">显示div3显示div3显示div3</a></li>
  64. <div id="divalt3" class="div1" style="display:none">显示div3<br />显示div3<br />显示div3</div>
  65. <li><a href="#" onmousemove="showdiv('divalt4','',event)" onmouseover="showdiv('divalt4','',event)" onmouseout="showdiv('divalt4','none')">显示div4显示div4显示div4</a></li>
  66. <div id="divalt4" class="div1" style="display:none">显示div4<br />显示div4<br />显示div4</div>
  67. </ul>
  68. </body>
  69. </html>

 

文章评论(查看全部)

昵 称 *
电子邮箱 *
网 址      9 + 8 = ?