Created
December 14, 2017 13:48
-
-
Save af23me/c25914acb0f8732ba6aacf8578bb7929 to your computer and use it in GitHub Desktop.
Extend Bootstrap 3 Popover positions
This file contains hidden or 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
.popover.topLeft { | |
margin-top: -10px; | |
} | |
.popover.topLeft .arrow { | |
bottom: -11px; | |
left: 20%; | |
margin-left: -11px; | |
border-top-color: #999999; | |
border-top-color: rgba(0, 0, 0, 0.25); | |
border-bottom-width: 0; | |
} | |
.popover.topLeft .arrow:after { | |
bottom: 1px; | |
margin-left: -10px; | |
border-top-color: #ffffff; | |
border-bottom-width: 0; | |
content: " "; | |
} | |
/** Top Right **/ | |
.popover.topRight { | |
margin-top: -10px; | |
} | |
.popover.topRight .arrow { | |
bottom: -11px; | |
left: 80%; | |
margin-left: -11px; | |
border-top-color: #999999; | |
border-top-color: rgba(0, 0, 0, 0.25); | |
border-bottom-width: 0; | |
} | |
.popover.topRight .arrow:after { | |
bottom: 1px; | |
margin-left: -10px; | |
border-top-color: #ffffff; | |
border-bottom-width: 0; | |
content: " "; | |
} | |
/************************* | |
* Right Positions | |
*************************/ | |
/** Right Top **/ | |
.popover.rightTop { | |
margin-left: 10px; | |
} | |
.popover.rightTop .arrow { | |
top: 20%; | |
left: -11px; | |
margin-top: -11px; | |
border-right-color: #999999; | |
border-right-color: rgba(0, 0, 0, 0.25); | |
border-left-width: 0; | |
} | |
.popover.rightTop .arrow:after { | |
bottom: -10px; | |
left: 1px; | |
border-right-color: #ffffff; | |
border-left-width: 0; | |
content: " "; | |
} | |
/** Right Bottom **/ | |
.popover.rightBottom { | |
margin-left: 10px; | |
} | |
.popover.rightBottom .arrow { | |
top: 80%; | |
left: -11px; | |
margin-top: -11px; | |
border-right-color: #999999; | |
border-right-color: rgba(0, 0, 0, 0.25); | |
border-left-width: 0; | |
} | |
.popover.rightBottom .arrow:after { | |
bottom: -10px; | |
left: 1px; | |
border-right-color: #ffffff; | |
border-left-width: 0; | |
content: " "; | |
} | |
/************************* | |
* Bottom Positions | |
*************************/ | |
/** Bottom Left **/ | |
.popover.bottomLeft { | |
margin-top: 10px; | |
} | |
.popover.bottomLeft .arrow { | |
top: -11px; | |
left: 20%; | |
margin-left: -11px; | |
border-bottom-color: #999999; | |
border-bottom-color: rgba(0, 0, 0, 0.25); | |
border-top-width: 0; | |
} | |
.popover.bottomLeft .arrow:after { | |
top: 1px; | |
margin-left: -10px; | |
border-bottom-color: #ffffff; | |
border-top-width: 0; | |
content: " "; | |
} | |
/** Bottom Right **/ | |
.popover.bottomRight { | |
margin-top: 10px; | |
} | |
.popover.bottomRight .arrow { | |
top: -11px; | |
left: 80%; | |
margin-left: -11px; | |
border-bottom-color: #999999; | |
border-bottom-color: rgba(0, 0, 0, 0.25); | |
border-top-width: 0; | |
} | |
.popover.bottomRight .arrow:after { | |
top: 1px; | |
margin-left: -10px; | |
border-bottom-color: #ffffff; | |
border-top-width: 0; | |
content: " "; | |
} | |
/************************* | |
* Left Positions | |
*************************/ | |
/** Left Top **/ | |
.popover.leftTop { | |
margin-left: -10px; | |
} | |
.popover.leftTop .arrow { | |
top: 20%; | |
right: -11px; | |
margin-top: -11px; | |
border-left-color: #999999; | |
border-left-color: rgba(0, 0, 0, 0.25); | |
border-right-width: 0; | |
} | |
.popover.leftTop .arrow:after { | |
right: 1px; | |
bottom: -10px; | |
border-left-color: #ffffff; | |
border-right-width: 0; | |
content: " "; | |
} | |
/** Left Bottom **/ | |
.popover.leftBottom { | |
margin-left: -10px; | |
} | |
.popover.leftBottom .arrow { | |
top: 80%; | |
right: -11px; | |
margin-top: -11px; | |
border-left-color: #999999; | |
border-left-color: rgba(0, 0, 0, 0.25); | |
border-right-width: 0; | |
} | |
.popover.leftBottom .arrow:after { | |
right: 1px; | |
bottom: -10px; | |
border-left-color: #ffffff; | |
border-right-width: 0; | |
content: " "; | |
} |
This file contains hidden or 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
(function($) { | |
$.fn.popover.Constructor.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) { | |
var result; | |
switch (placement) { | |
case 'bottom': | |
result = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}; | |
break; | |
case 'top': | |
result = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}; | |
break; | |
case 'left': | |
result = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}; | |
break; | |
case 'right': | |
result = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}; | |
break; | |
// extend placements (top) | |
case 'topLeft': | |
result = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - (actualWidth * .20)}; | |
break; | |
case 'topRight': | |
result = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - (actualWidth * .80)}; | |
break; | |
// extend placements (right) | |
case 'rightTop': | |
result = {top: pos.top + pos.height / 2 - (actualHeight *.20), left: pos.left + pos.width}; | |
break; | |
case 'rightBottom': | |
result = {top: pos.top + pos.height / 2 - (actualHeight * .80), left: pos.left + pos.width}; | |
break; | |
// extend placements (bottom) | |
case 'bottomLeft': | |
result = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - (actualWidth * .20)}; | |
break; | |
case 'bottomRight': | |
result = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - (actualWidth * .80)}; | |
break; | |
// extend placements (left) | |
case 'leftTop': | |
result = {top: pos.top + pos.height / 2 - (actualHeight *.20), left: pos.left - actualWidth}; | |
break; | |
case 'leftBottom': | |
result = {top: pos.top + pos.height / 2 - (actualHeight * .80), left: pos.left - actualWidth}; | |
break; | |
default: | |
/* placement == 'top' */ | |
result = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2} | |
break; | |
} | |
return result; | |
}; | |
})(jQuery); |
This file contains hidden or 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
<script type="text/javascript" src="/bootstrap/js/bootstrap.min.js"></script> | |
<script type="text/javascript" src="bootstrap-popover-extension.js"></script> | |
<link rel="stylesheet" type="text/css" href="bootstrap-popover-extension.css"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment