Skip to content

Instantly share code, notes, and snippets.

@khoand0000
Created December 26, 2015 11:53
Show Gist options
  • Save khoand0000/41974a2735abb322e61a to your computer and use it in GitHub Desktop.
Save khoand0000/41974a2735abb322e61a to your computer and use it in GitHub Desktop.
solution for multiple modals overlay

I copied the solution from link: http://stackoverflow.com/questions/19305821/multiple-modals-overlay

$(document).on('show.bs.modal', '.modal', function () {
    var zIndex = 1040 + (10 * $('.modal:visible').length);
    $(this).css('z-index', zIndex);
    setTimeout(function() {
        $('.modal-backdrop').not('.modal-stack').css('z-index', zIndex - 1).addClass('modal-stack');
    }, 0);
});

Scrollbar fix

If you have a modal on your page that exceeds the browser height, then you can't scroll in it when closing an second modal. To fix this add:

$(document).on('hidden.bs.modal', '.modal', function () {
    $('.modal:visible').length && $(document.body).addClass('modal-open');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment