我遇到了 PopOver 的问题。我希望它能够在所有位置自动调整。如果右侧找不到空间,则会从左侧打开。但我希望它对顶部/底部做同样的事情。即,如果顶部找不到空间,则应在底部打开,反之亦然。难道我就没有什么办法可以为各方做到这一点吗?
$('[data-toggle="popover"]').popover({
trigger: 'manual',
placement: 'auto right'
})
The 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 or a 返回字符串的函数:
$('[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";
}
});
对于上下文,此代码的来源是根据弹出窗口相对于窗口边缘的 X 位置更改 Bootstrap 弹出窗口的位置? https://stackoverflow.com/questions/9956958/changing-the-position-of-bootstrap-popovers-based-on-the-popovers-x-position-in(它声明不需要归属 - 只需将其添加为资源)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)