Skip to content

Instantly share code, notes, and snippets.

@connordavison
Last active October 26, 2015 15:25
Show Gist options
  • Select an option

  • Save connordavison/9cb59d7a668bcec7a149 to your computer and use it in GitHub Desktop.

Select an option

Save connordavison/9cb59d7a668bcec7a149 to your computer and use it in GitHub Desktop.
Make an element popup over another.
$.fn.popup = function (tooltip) {
var targets = $(this);
targets.click(function () {
var target = $(this);
var desired = {
left: target.position().left + target.width() / 2,
top: target.position().top - tooltip.height()
};
var current = tooltip.position();
if (current.left == desired.left && current.top == desired.top) {
tooltip.hide();
} else {
tooltip.show();
tooltip.offset(desired);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment