我有一个项目列表,每个项目都有一个与之关联的 Bootstrap 弹出窗口 ( docs here )。它们是这样启动的:
$('#my_list li').popover({
placement: 'left'
});
这行得通,但在宽度较小时,弹出框会从视口(viewport)中消失。我想根据 $(document).width();
设置条件放置,但是我看不到覆盖初始选项的方法(例如,在宽度为1000px,将位置切换到“上方”)。
我整理了一个简化版本 at jsfiddle here .非常感谢。
最佳答案
placement 也可以取一个函数作为它的值。在此函数中,您可以根据视口(viewport)的宽度返回适当的值。例如。
$(document).ready(function(){
$('#my_list li').popover({
placement: wheretoplace
});
});
function wheretoplace(){
var width = window.innerWidth;
if (width<500) return 'bottom';
return 'left';
}
关于javascript - 是否可以根据屏幕宽度更改 Bootstrap 弹出窗口的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8166101/