2011-11-17 93 views
5

我有一个项目列表,每个项目都有一个与之相关的Bootstrap弹出窗口(docs here)。这些计划是这样的:是否可以根据屏幕宽度更改Bootstrap弹出窗口的位置?

$('#my_list li').popover({ 
    placement: 'left' 
}); 

这工作,但小宽的酥料饼从视丢失。我想根据$(document).width();进行条件设置,但是我看不到一种方法来覆盖最初的选项(例如,宽度大约为1000px,将展示位置切换到“上方”​​)。

我已经放在一起简化版本at jsfiddle here。非常感谢。

回答

20

展示位置也可以采用一个函数作为它的值。在这个函数中,你可以根据视口的宽度返回适当的值。例如。从左至右

$(document).ready(function(){ 
    $('#my_list li').popover({ 
     placement: wheretoplace 
    }); 
}); 
function wheretoplace(){ 
    var width = window.innerWidth; 
    if (width<500) return 'bottom'; 
    return 'left'; 
} 
+0

完美的顶部 - 谢谢。我现在感觉有点愚蠢。 – CherryFlavourPez

+1

无法正常工作。 popover仍然在边缘。我正在使用BS3 –

0

及其变化放置到窗口小于768

placement: function(){return $(window).width()>768 ? "auto left":"auto top";}