有什么方法可以根据窗口宽度更改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'
})
最佳答案
更改窗口大小时,可以销毁并重新创建弹出窗口:
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'
});
}
关于jquery - 如何动态更改Bootstrap弹出窗口的位置?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50461006/