Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. Javascript:
  2.  
  3. function tooltip() {
  4. var title = $(this).attr("title");
  5. $(this).removeAttr("title");
  6.  
  7. this.TooltipMessage = $("<div />", {class: "tooltipMessage", style: "display: none;"});
  8. this.TooltipMessage.html("<span>" + title + "</span>");
  9. $("body").append(this.TooltipMessage);
  10.  
  11.  
  12. if ($(this).hasClass("tooltipLeft")) {
  13. this.TooltipMessage.addClass("left");
  14. }
  15.  
  16. $(this).hover(tooltipFadeIn, tooltipFadeOut);
  17. $(this).mousemove(tooltipMousemove);
  18. }
  19.  
  20. function tooltipFadeIn() {
  21. this.TooltipMessage.stop(true, false).fadeIn();
  22. }
  23.  
  24. function tooltipFadeOut() {
  25. this.TooltipMessage.stop(true, false).fadeOut();
  26. }
  27.  
  28. function tooltipMousemove(e) {
  29. var offset = {
  30. left: e.pageX,
  31. top: e.pageY + 10
  32. };
  33.  
  34. if (this.TooltipMessage.hasClass("left")) {
  35. offset.left -= this.TooltipMessage.width() + 10;
  36. } else {
  37. offset.left += 25;
  38. }
  39.  
  40. this.TooltipMessage.offset(offset);
  41. }
  42.  
  43. $(function (e) {
  44. $(".tooltip").each(tooltip);
  45. });
  46.  
  47.  
  48. CSS:
  49. div.tooltipMessage {
  50. z-index: 9001; /* It's over 9000! :D */
  51. position: absolute;
  52. width: 400px;
  53. text-align: left;
  54. }
  55. div.tooltipMessage > span {
  56. display: inline-block;
  57. background: black;
  58. background-color: rgba(0, 0, 0, .8);
  59. border-radius: 0 5px 5px 5px;
  60. padding: 2px 5px;
  61. color: white;
  62. }
  63. div.tooltipMessage.left > span {
  64. float: right;
  65. border-radius: 5px 0 5px 5px;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement