在项目中遇到了这个问题,在网上搜索后,找到了解决办法 所以在此记录下
废话不多说 上代码
// 弹出层垂直居中
$('#myModal').on('show.bs.modal', centerModals);
/**
* 弹出层垂直居中
*/
function centerModals() {
$('#myModal').each(function(i) {
var $clone = $(this).clone().css('display','block').appendTo('body');
var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 2);
top = top > 0 ? top : 0;
$clone.remove();
$(this).find('.modal-content').css("margin-top", top);
});
};