Use modal in a modal after closing the second modal, the scrolling refers to the body

血红的双手。 提交于 2019-12-02 08:27:24

When dealing with bootstrap stacked modal, most common problems are

  1. 2nd modal overlay appearing behind first modal
  2. on closing 2nd modal, scrolling disappear because modal-open removed from <body>

both problems can be solved with custom code as suggested by bootstrap

Multiple open modals not supported
Be sure not to open a modal while another is still visible. Showing more than one modal at a time requires custom code.

$(document).ready(function () {
    $('secondmodalselector').on('show.bs.modal', function () {
        $('firstmodalselector').css('z-index', 1039); //this will push the first modal overlay behind second modal overlay
    });

    $('secondmodalselector').on('hidden.bs.modal', function () {
        $('firstmodalselector').css('z-index', 1041); //bring back the first modal overlay to it's normal state when 2nd modal closed
        $('body').addClass('modal-open'); // add `modal-open` class back to body when 2nd modal close so first modal will be scrollable
    });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!