Created
March 4, 2016 15:31
-
-
Save grena/faaa75d869181a9027ad to your computer and use it in GitHub Desktop.
Automatic placement for bootstrap popover
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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