Bootstrap Modals keep adding padding-right to body after closed

后端 未结 30 1828
南方客
南方客 2020-12-12 12:36

I am using bootstrap and Parse framework to build a small webapp. But those Bootstrap modals keep adding padding-right to body after closed. How to solve this?

I tri

相关标签:
30条回答
  • 2020-12-12 13:21

    I have just used the css fix below and it is working for me

    body { padding-right: 0 !important }
    
    0 讨论(0)
  • 2020-12-12 13:21

    I have same problem with Bootstrap 3.3.7 and my solution for fixed navbar: Adding this style to your custom css.

    .modal-open {
        padding-right: 0px !important;
        overflow-y: scroll;
    }
    

    it will make your modal showed while scroll window still working. thanks, hope this will help you too

    0 讨论(0)
  • 2020-12-12 13:22

    removeAttr won't work you will to remove the CSS property like this:

            $('.modal').on('hide.bs.modal', function (e) {
                e.stopPropagation();
                $('body').css('padding-right','');
            }); 
    

    With no property value, the property is removed.

    0 讨论(0)
  • 2020-12-12 13:22

    I dug into the bootstrap javascript and found that the Modal code sets the right padding in a function called adjustDialog() which is defined on the Modal prototype and exposed on jQuery. Placing the following code somewhere to override this function to do nothing did the trick for me (although I don't know what the consequence of not setting this is yet!!)

    $.fn.modal.Constructor.prototype.adjustDialog = function () { };

    0 讨论(0)
  • 2020-12-12 13:23

    This might be a glitch from Bootstrap modal. From my tests, it seems like the problem is that #adminPanel is being initialized while #loginModal has not been totally closed yet. The workarounds can be removing the animation by removing the fade class on #adminPanel and #loginModal or set a timeout (~500ms) before calling $('#adminPanel').modal();. Hope this helps.

    0 讨论(0)
  • 2020-12-12 13:23
    $('.modal').on('hide.bs.modal,hidden.bs.modal', function () {
     setTimeout(function(){
      $('body').css('padding-right',0);
     },1000);
    });
    

    Try this

    It will add the padding right 0px to the body after the modal close.

    0 讨论(0)
提交回复
热议问题