javascript经典效果(三)

13年前

二 鼠标旁边的提示信息,类似与163登录后的

页面

提示

效果


  1. <a href="#" title="这是提示">tip</a>
  2. <script Language="JavaScript">
  3. //***********默认设置定义.*********************
  4. tPopWait=50;//停留tWait豪秒后显示提示。
  5. tPopShow=5000;//显示tShow豪秒后关闭提示
  6. showPopStep=20;
  7. popOpacity=99;
  8. //***************内部变量定义*****************
  9. sPop=null;
  10. curShow=null;
  11. tFadeOut=null;
  12. tFadeIn=null;
  13. tFadeWaiting=null;
  14. document.write("<style type='text/css'id='defaultPopStyle'>");
  15. 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)}");
  16. document.write("</style>");
  17. document.write("<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");
  18. function showPopupText(){
  19. var o=event.srcElement;
  20. MouseX=event.x;
  21. MouseY=event.y;
  22. if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
  23. if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
  24. if(o.dypop!=sPop) {
  25. sPop=o.dypop;
  26. clearTimeout(curShow);
  27. clearTimeout(tFadeOut);
  28. clearTimeout(tFadeIn);
  29. clearTimeout(tFadeWaiting);
  30. if(sPop==null || sPop=="") {
  31. dypopLayer.innerHTML="";
  32. dypopLayer.style.filter="Alpha()";
  33. dypopLayer.filters.Alpha.opacity=0;
  34. }
  35. else {
  36. if(o.dyclass!=null) popStyle=o.dyclass
  37. else popStyle="cPopText";
  38. curShow=setTimeout("showIt()",tPopWait);
  39. }
  40. }
  41. }
  42. function showIt(){
  43. dypopLayer.className=popStyle;
  44. dypopLayer.innerHTML=sPop;
  45. popWidth=dypopLayer.clientWidth;
  46. popHeight=dypopLayer.clientHeight;
  47. if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
  48. else popLeftAdjust=0;
  49. if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
  50. else popTopAdjust=0;
  51. dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
  52. dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;
  53. dypopLayer.style.filter="Alpha(Opacity=0)";
  54. fadeOut();
  55. }
  56. function fadeOut(){
  57. if(dypopLayer.filters.Alpha.opacity<popOpacity) {
  58. dypopLayer.filters.Alpha.opacity+=showPopStep;
  59. tFadeOut=setTimeout("fadeOut()",1);
  60. }
  61. else {
  62. dypopLayer.filters.Alpha.opacity=popOpacity;
  63. tFadeWaiting=setTimeout("fadeIn()",tPopShow);
  64. }
  65. }
  66. function fadeIn(){
  67. if(dypopLayer.filters.Alpha.opacity>0) {
  68. dypopLayer.filters.Alpha.opacity-=1;
  69. tFadeIn=setTimeout("fadeIn()",1);
  70. }
  71. }
  72. document.onmouseover=showPopupText;
  73. </script>
复制代码