jQuery.fn.elementlocation = function() {
var curleft = 0;
var curtop = 0;
var obj = this;
do {
curleft += obj.attr('offsetLeft');
curtop += obj.attr('offsetTop');
obj = obj.offsetParent();
} while ( obj.attr('tagName') != 'BODY' );
return ( {x:curleft, y:curtop} );
};
$(document).ready(function() {
var close = true;
var popup = $("#popup");
$(".zoekcloud a").each(function() {
$(this).hover(function() {
var location = $(this).elementlocation();
close = true;
showPopup(popup, location, $(this));
}, function() {
setInterval(checkClose(), 2000);
});
});
function checkClose() {
if (!close) {
closePopup(popup);
}
}
function showPopup(popup, e, obj) {
popup.hover(function() {
close = true;
}, close = false);
x = e.x;
y = e.y;
popup.html("Hallo Thijs");
popup.css('top', y+241);
popup.css('left', x+300);
popup.css('position', 'absolute');
popup.css('display', '');
popup.css('width', '300px');
popup.css('height', '0px');
popup.animate({
height: "200px",
}, 500, 'linear');
}
function closePopup(popup) {
console.log('close');
popup.hide(200);
}
});