PopOver自动调整位置 [英] PopOver auto adjust placement
问题描述
我正遇到PopOver问题.我希望它在所有位置都自动调整.如果在右侧找不到空间,则会在左侧打开.但我希望它对顶部/底部执行相同的操作.即,如果在顶部找不到空间,则应在底部打开,反之亦然.我没有办法全方位地做到这一点吗?
I am facing an issue with PopOver. I want it to auto adjust at all positions. If it doesn't find space on right side it opens at left. But I want it to do the same thing for top/bottom. i.e if it doesn't find space at top it should open at bottom and vice versa. Isn't there any way I can do it for all sides?
$('[data-toggle="popover"]').popover({
trigger: 'manual',
placement: 'auto right'
})
HTML
<a data-toggle="popover" class="hlpicon" data-html="true" data-trigger="hover" data-container="body" data-content="This will open a popover" data-original-title="" title=""></a>
推荐答案
您应该能够将placement
选项用作返回字符串的 string 或函数 strong>:
You should be able to use the placement
option as either a string or a function returning a string:
$('[data-toggle="popover"]').popover({
trigger: 'manual',
placement: function (context, source) {
var position = $(source).position();
if (position.left > 515) {
return "left";
}
if (position.left < 515) {
return "right";
}
if (position.top < 110){
return "bottom";
}
return "top";
}
});
For context, the source of this code is Changing the position of Bootstrap popovers based on the popover's X position in relation to window edge? (which declares attribution to be not required - just adding this as a resource).
这篇关于PopOver自动调整位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!