bootstrap默认的模态窗弹出双层时是有问题的,一般第二个弹出的窗口会在第一个窗口遮罩层的下边,并且样式也会被影响掉;
按照以下方法,就可以显示双层弹出,并且如果第一层有滚动条,也不会影响第一层的滚动条;
一,首先第二层的弹框要加一个隐藏的样式;
例如:
<div class="modal fade " id="talkAndVideo_model" tabindex="-1" role="dialog" style="display: none" aria-labelledby="myModalLabel"
二,将以下方法直接粘到js内
$(document).on('show.bs.modal', '.modal', function(event) {
$(this).appendTo($('body'));
}).on('shown.bs.modal', '.modal.in', function(event) {
setModalsAndBackdropsOrder();
}).on('hidden.bs.modal', '.modal', function(event) {
// setModalsAndBackdropsOrder();
//触发隐藏事件时
//优化第二层弹出后再关闭时,影响了第一层的滚动条
if ($('.modal.in').size() >= 1) {
$('body').addClass('modal-open')
}
});
function setModalsAndBackdropsOrder() {
var modalZIndex = 1040;
$('.modal.in').each(function(index) {
var $modal = $(this);
modalZIndex++;
$modal.css('zIndex', modalZIndex);
$modal.next('.modal-backdrop.in').addClass('hidden').css('zIndex', modalZIndex - 1);
});
$('.modal.in:visible:last').focus().next('.modal-backdrop.in').removeClass('hidden');
}