public
Last active

  • Download Gist
jquery.pop.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
;(function($) {
 
$.fn.pop = function(options) {
 
var defaults = {
distance: 10,
time: 250,
delay: 500,
// pop: selector or element to show when this is hovered over
};
var s = $.extend(defaults, options);
 
return this.each(function() {
var hideDelayTimer = false,
beingShown = false,
shown = false;
 
$(this).mouseover(function() {
if (hideDelayTimer)
clearTimeout(hideDelayTimer);
if (beingShown || shown) {
return;
} else {
beingShown = true;
var doneMouseOver = function() {
beingShown = false;
shown = true
};
var offset = $(this).offset();
 
$(s.pop)
.show()
.css({position: "absolute",
top: offset.top - $(this).height() - $(s.pop).height(),
left: offset.left})
.animate({top: '-='+s.distance+'px', opacity:1}, s.time, 'swing', doneMouseOver);
}
}).mouseout(function() {
if (hideDelayTimer)
clearTimeout(hideDelayTimer);
 
var doneMouseOut = function() {
shown = false;
$(s.pop).hide();
};
hideDelayTimer = setTimeout(function() {
hideDelayTimer = false;
$(s.pop).animate({top:'-='+s.distance+'px', opacity: 0}, s.time, 'swing', doneMouseOut)
}, s.delay);
 
});
});
 
};
 
})(jQuery);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.