1. jQuery.fn.elementlocation = function() {
  2. var curleft = 0;
  3. var curtop = 0;
  4.  
  5. var obj = this;
  6.  
  7. do {
  8. curleft += obj.attr('offsetLeft');
  9. curtop += obj.attr('offsetTop');
  10.  
  11. obj = obj.offsetParent();
  12. } while ( obj.attr('tagName') != 'BODY' );
  13. return ( {x:curleft, y:curtop} );
  14. };
  15. $(document).ready(function() {
  16.  
  17. var close = true;
  18.  
  19. var popup = $("#popup");
  20. $(".zoekcloud a").each(function() {
  21. $(this).hover(function() {
  22. var location = $(this).elementlocation();
  23. close = true;
  24. showPopup(popup, location, $(this));
  25. }, function() {
  26. setInterval(checkClose(), 2000);
  27. });
  28. });
  29.  
  30. function checkClose() {
  31. if (!close) {
  32. closePopup(popup);
  33. }
  34. }
  35. function showPopup(popup, e, obj) {
  36. popup.hover(function() {
  37. close = true;
  38. }, close = false);
  39. x = e.x;
  40. y = e.y;
  41. popup.html("Hallo Thijs");
  42. popup.css('top', y+241);
  43. popup.css('left', x+300);
  44. popup.css('position', 'absolute');
  45. popup.css('display', '');
  46. popup.css('width', '300px');
  47. popup.css('height', '0px');
  48. popup.animate({
  49. height: "200px",
  50. }, 500, 'linear');
  51. }
  52.  
  53. function closePopup(popup) {
  54. console.log('close');
  55. popup.hide(200);
  56. }
  57. });