有没有办法根据窗口宽度更改Bootstraps Popover位置/位置?我用它来显示一些额外的表单项,需要在左侧网站上显示,但在移动设备上显示。所以基本上当屏幕变小时 - 我需要改变位置。
jQuery('#monthly-expenses').popover({
content: jQuery('#monthly-expense-datails'),
placement() {
let placement = 'left';
if (jQuery(window).width() <= 992) {
placement = 'top';
}
return placement;
},
html: true,
trigger: 'manual'
})
答案 0 :(得分:0)
更改窗口大小时,您可以销毁并重新创建弹出窗口:
var placement;
jQuery(window).on('resize',function(){
if (jQuery(window).width() <= 992 && placement == 'left') {//when the width is right and we did't change placement
placement = 'top';
jQuery('#monthly-expenses').popover('dispose');//destroy the
createPopover(placement);//create it with the new placement
} else if (jQuery(window).width() > 992 && placement == 'top')
placement = 'left';
jQuery('#monthly-expenses').popover('dispose');//destroy the popover
createPopover(placement);//create it with the new placement
}
});
function createPopover(placement) {
jQuery('#monthly-expenses').popover({
content: jQuery('#monthly-expense-datails'),
placement:placement,
html: true,
trigger: 'manual'
});
}