bootstrap-model實現雙層彈框;

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');
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章