Furamente

tooltip

Jul 1st, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. var tooltip=function(){
  2. var id = 'tt';
  3. var top = 3;
  4. var left = 3;
  5. var maxw = 300;
  6. var speed = 25;
  7. var timer = 20;
  8. var endalpha = 95;
  9. var alpha = 0;
  10. var tt,t,c,b,h;
  11. var ie = document.all ? true : false;
  12. return{
  13. show:function(v,w){
  14. this.onmouseout='tooltip.hide()';
  15. if(tt == null){
  16. tt = document.createElement('div');
  17. tt.setAttribute('id',id);
  18. t = document.createElement('div');
  19. t.setAttribute('id',id + 'top');
  20. c = document.createElement('div');
  21. c.setAttribute('id',id + 'cont');
  22. b = document.createElement('div');
  23. b.setAttribute('id',id + 'bot');
  24. tt.appendChild(t);
  25. tt.appendChild(c);
  26. tt.appendChild(b);
  27. document.body.appendChild(tt);
  28. tt.style.opacity = 0;
  29. tt.style.filter = 'alpha(opacity=0)';
  30. document.onmousemove = this.pos;
  31. }
  32. tt.style.display = 'block';
  33. c.innerHTML = v;
  34. tt.style.width = w ? w + 'px' : 'auto';
  35. if(!w && ie){
  36. t.style.display = 'none';
  37. b.style.display = 'none';
  38. tt.style.width = tt.offsetWidth;
  39. t.style.display = 'block';
  40. b.style.display = 'block';
  41. }
  42. if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
  43. h = parseInt(tt.offsetHeight) + top;
  44. clearInterval(tt.timer);
  45. tt.timer = setInterval(function(){tooltip.fade(1)},timer);
  46. },
  47. pos:function(e){
  48. var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
  49. var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
  50. tt.style.top = (u - h) + 'px';
  51. tt.style.left = (l + left) + 'px';
  52. },
  53. fade:function(d){
  54. var a = alpha;
  55. if((a != endalpha && d == 1) || (a != 0 && d == -1)){
  56. var i = speed;
  57. if(endalpha - a < speed && d == 1){
  58. i = endalpha - a;
  59. }else if(alpha < speed && d == -1){
  60. i = a;
  61. }
  62. alpha = a + (i * d);
  63. tt.style.opacity = alpha * .01;
  64. tt.style.filter = 'alpha(opacity=' + alpha + ')';
  65. }else{
  66. clearInterval(tt.timer);
  67. if(d == -1){tt.style.display = 'none'}
  68. }
  69. },
  70. hide:function(){
  71. clearInterval(tt.timer);
  72. tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
  73. }
  74. };
  75. }();
Advertisement
Add Comment
Please, Sign In to add comment