Skip to content

Instantly share code, notes, and snippets.

@grena
Created March 4, 2016 15:31
Show Gist options
  • Save grena/faaa75d869181a9027ad to your computer and use it in GitHub Desktop.
Save grena/faaa75d869181a9027ad to your computer and use it in GitHub Desktop.
Automatic placement for bootstrap popover
// Source https://github.com/twbs/bootstrap/issues/1833#issuecomment-4102195
placement: function (tip, element) {
var offset = $(element).offset();
height = $(document).outerHeight();
width = $(document).outerWidth();
vert = 0.5 * height - offset.top;
vertPlacement = vert > 0 ? 'bottom' : 'top';
horiz = 0.5 * width - offset.left;
horizPlacement = horiz > 0 ? 'right' : 'left';
placement = Math.abs(horiz) > Math.abs(vert) ? horizPlacement : vertPlacement;
return placement;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment