Guest User

Untitled

a guest
Feb 17th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. $(document).ready(function() {
  2.  
  3. var $parent,
  4. windowWidth,
  5. windowHeight;
  6.  
  7. //get actual window size
  8. function winSize() {
  9. windowWidth = $(window).width(),
  10. windowHeight = $(window).height();
  11. }
  12. winSize();
  13. $(window).resize(winSize);
  14. //tooltip fadeIn and fadeOut on hover
  15. $('.tooltip').each(function() {
  16.  
  17. $(this).parent().hover(function() {
  18. $(this).find('.tooltip').fadeIn('fast');
  19. }, function() {
  20. $(this).find('.tooltip').fadeOut('fast');
  21. });
  22.  
  23. });
  24.  
  25.  
  26. //tooltip position
  27. $(document).mousemove(function(e) {
  28. var mouseY = e.clientY,
  29. mouseX = e.clientX,
  30. tooltipHeight,
  31. tooltipWidth;
  32.  
  33. $('.tooltip').each(function() {
  34. var $tooltip = $(this);
  35. tooltipHeight = $tooltip.outerHeight();
  36. tooltipWidth = $tooltip.width();
  37. $parent = $tooltip.parent();
  38.  
  39. $tooltip.css({
  40. 'left':mouseX,
  41. 'top':mouseY+20
  42. });
  43.  
  44. //reposition
  45. if (tooltipWidth + mouseX+ 20> windowWidth) {
  46. $tooltip.css({
  47. 'left':mouseX-tooltipWidth-20
  48. });
  49. }
  50.  
  51. if (tooltipHeight + mouseY +20 > windowHeight) {
  52. $tooltip.css({
  53. 'top':mouseY-20-tooltipHeight
  54. });
  55. }
  56. });//end each
  57. });//tooltip position
  58.  
  59.  
  60. });//end ready
Add Comment
Please, Sign In to add comment