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

前端 未结 1 950
太阳男子
太阳男子 2021-01-26 08:26

I am a new front end developer and I am having problem doing my project. I used modal in a modal and it works. My first modal is a long modal which needs to be scrolled to see t

相关标签:
1条回答
  • 2021-01-26 08:45

    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
        });
    });
    
    0 讨论(0)
提交回复
热议问题