Guest User

Untitled

a guest
Jul 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. /* Greatly inspired from GitHub */
  2. (function($) {
  3. $.fn.tip = function(options) {
  4. options = $.extend({gravity: "n", title: "title"}, options || {});
  5. this.hover(
  6. function() {
  7. var tip = $(this).data('active-tip');
  8. if(!tip) {
  9. tip = $('<div class="tip"><div class="tip-inner" /></div>');
  10. tip.css({position: "absolute",zIndex: 100000});
  11. $(this).data('active-tip', tip);
  12. }
  13. tip.find('.tip-inner').html($(this).attr(options.title));
  14. tip.remove().css({top:0,left:0,display:"block"}).appendTo($(document.body));
  15.  
  16. var tippedCoordinates = $.extend($(this).offset(), {width: this.offsetWidth, height: this.offsetHeight});
  17. var tipDimensions = {width: tip[0].offsetWidth, height: tip[0].offsetHeight};
  18. switch(options.gravity.charAt(0)) {
  19. case "n":
  20. tip.css({
  21. top: tippedCoordinates.top + tippedCoordinates.height,
  22. left: tippedCoordinates.left + tippedCoordinates.width / 2 - tipDimensions.width / 2
  23. }).addClass('tip-north');
  24. break;
  25. case "s":
  26. tip.css({
  27. top: tippedCoordinates.top - tipDimensions.height,
  28. left: tippedCoordinates.left + tippedCoordinates.width / 2 - tipDimensions.width / 2
  29. }).addClass('tip-south');
  30. break;
  31. case "e":
  32. tip.css({
  33. top: tippedCoordinates.top + tippedCoordinates.height / 2 - tipDimensions.height / 2,
  34. left: tippedCoordinates.left - tipDimensions.width
  35. }).addClass('tip-east');
  36. break;
  37. case "w":
  38. tip.css({
  39. top: tippedCoordinates.top + tippedCoordinates.height / 2 - tipDimensions.height / 2,
  40. left: tippedCoordinates.left + tippedCoordinates.width
  41. }).addClass('tip-west');
  42. break;
  43. }
  44. },
  45. function() {
  46. var tip = $(this).data('active-tip');
  47. tip.remove();
  48. }
  49. );
  50. };
  51. })(jQuery);
Add Comment
Please, Sign In to add comment