自定义Html的Title标签显示时间

Html代码中对每个标签都有Title属性,鼠标放到这个标签上的时候会出来相应的文字,但这个Title显示时间、关闭时间都无法自己控制,有的时候不得不写一个Div,再加上Onmouseover和Onmouseout事件来代替Title,很是麻烦。于是网上搜集了一下资料,自己写了一个可以自定义显示时间的Title,并且Title中还可以插入img标签来显示图片, 贴出来供大家分享。(只测试对IE有效,对其他浏览器没有测试)

将以代码保存为myTitle.js

  1. //***********默认设置定义.*********************
  2. tPopWait=50;//停留tWait豪秒后显示提示。
  3. tPopShow=500000;//显示tShow豪秒后关闭提示
  4. showPopStep=20;
  5. popOpacity=99;
  6. //***************内部变量定义*****************
  7. sPop=null;
  8. curShow=null;
  9. tFadeOut=null;
  10. tFadeIn=null;
  11. tFadeWaiting=null;
  12. document.write("<style type='text/css'id='defaultPopStyle'>");
  13. document.write(".cPopText { background-color: #F8F8F5;color:#000000; border: 1px #000000 solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}");
  14. document.write("</style>");
  15. document.write("<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");
  16. function showPopupText(){
  17. var o=event.srcElement;
  18. MouseX=event.x;
  19. MouseY=event.y;
  20. if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
  21. if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
  22. if(o.dypop!=sPop) {
  23. sPop=o.dypop;
  24. clearTimeout(curShow);
  25. clearTimeout(tFadeOut);
  26. clearTimeout(tFadeIn);
  27. clearTimeout(tFadeWaiting); 
  28. if(sPop==null || sPop=="") {
  29. dypopLayer.innerHTML="";
  30. dypopLayer.style.filter="Alpha()";
  31. dypopLayer.filters.Alpha.opacity=0; 
  32. }
  33. else {
  34. if(o.dyclass!=null) popStyle=o.dyclass 
  35. else popStyle="cPopText";
  36. curShow=setTimeout("showIt()",tPopWait);
  37. }
  38. }
  39. }
  40. function showIt(){
  41. dypopLayer.className=popStyle;
  42. dypopLayer.innerHTML=sPop;
  43. popWidth=dypopLayer.clientWidth;
  44. popHeight=dypopLayer.clientHeight;
  45. //此处设置Title显示的位置
  46. if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
  47. else popLeftAdjust=0;
  48. if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
  49. else popTopAdjust=0;
  50. dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
  51. dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;
  52. dypopLayer.style.filter="Alpha(Opacity=0)";
  53. fadeOut();
  54. }
  55. function fadeOut(){
  56. if(dypopLayer.filters.Alpha.opacity<popOpacity) {
  57. dypopLayer.filters.Alpha.opacity+=showPopStep;
  58. tFadeOut=setTimeout("fadeOut()",1);
  59. }
  60. else {
  61. dypopLayer.filters.Alpha.opacity=popOpacity;
  62. tFadeWaiting=setTimeout("fadeIn()",tPopShow);
  63. }
  64. }
  65. function fadeIn(){
  66. if(dypopLayer.filters.Alpha.opacity>0) {
  67. dypopLayer.filters.Alpha.opacity-=1;
  68. tFadeIn=setTimeout("fadeIn()",1);
  69. }
  70. }
  71. document.οnmοuseοver=showPopupText;
  72. function CheckAll(form) {
  73. for (var i=0;i<form.elements.length;i++) {
  74. var e = form.elements[i];
  75. if (e.name != 'chkall') e.checked = form.chkall.checked; 
  76. }
  77. }

 

网页中引用代码,其实就和正常的网页一样,只不过引用了刚才那个JS文件而已

  1. <html>
  2. <head>
  3. <script src="myTitle.js" type="text/javascript"></script>
  4. </head>
  5. <body>
  6. <div title="test<br/><img src='w.jpg' />itasdf">ddsf</div>
  7. </body>
  8. </html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值