Skip to content

Instantly share code, notes, and snippets.

@dexcell
Created February 26, 2020 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dexcell/498c16edc3b6022db841064e4e1142c4 to your computer and use it in GitHub Desktop.
Save dexcell/498c16edc3b6022db841064e4e1142c4 to your computer and use it in GitHub Desktop.
Bootstrap 4 Stacked Modal
$('.modal').on('show.bs.modal', function () {
var $modal = $(this);
var baseZIndex = 1050;
var modalZIndex = baseZIndex + ($('.modal.show').length * 20);
var backdropZIndex = modalZIndex - 10;
$modal.css('z-index', modalZIndex).css('overflow', 'auto');
$('.modal-backdrop.show:last').css('z-index', backdropZIndex);
});
$('.modal').on('shown.bs.modal', function () {
var baseBackdropZIndex = 1040;
$('.modal-backdrop.show').each(function (i) {
$(this).css('z-index', baseBackdropZIndex + (i * 20));
});
});
$('.modal').on('hide.bs.modal', function () {
var $modal = $(this);
$modal.css('z-index', '');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment