Bootstrap modal: background jumps to top on toggle

后端 未结 30 3116
栀梦
栀梦 2020-11-29 19:48

I have a problem, with a modal. I have a button on a page, that toggles the modal. When the modal shows up, the page jumps to top.

I have done everything I could to

相关标签:
30条回答
  • 2020-11-29 20:04

    I was facing the same issue. Problem was I was adding .modal-open class to html and body elements. Just add this class to body and everything work as expected.

    0 讨论(0)
  • 2020-11-29 20:06

    I tried all of the above examples - this is the only thing that worked for me:

    .modal-open {
    
                padding-right: 0 !important;
    
            }
    

    Removing the padding from the right side of the model - prevents the jump.

    0 讨论(0)
  • 2020-11-29 20:07

    In bootstrap 3.1.1 I solved with this solution:

    body.modal-open {
        position: absolute !important;
    }
    
    0 讨论(0)
  • 2020-11-29 20:07

    I find it easier with this:

    overflow-y: hidden;
    

    When applied to the body class on modal opening - this prevents the vertical scroll of the body in the background and allows the user to stay in the same place without the scroll to top also.

    0 讨论(0)
  • 2020-11-29 20:09

    I spent hours on this trying everything here and elsewhere. For angularjs-material usage, turned out I had to disable animation on the uibModal.open config object arg.

    For example:

      $uibModal.open(
        {
          animation: false,
          component: 'myDialogComponent',
          size: 'lg',
          resolve: {
            details: function() {
              return detailsCollection;
            }
          }
        }
      );
    

    Hope this helps someone else.

    0 讨论(0)
  • 2020-11-29 20:10

    I got the same issue and none of answers helped me. Found a workaround which looks stupid but it works at least in my case.

    I found that page is scrolling to top only once and after that next opened modals works as expected. Than I found that hiding of any element in the DOM initiates the same strange scroll. So I just creating a dummy div after page load than hidding and removing it and this solved the issue.

    var $dummy= $("<div>");
    $("body").append($dummy);
    $dummy.hide().remove();
    
    0 讨论(0)
提交回复
热议问题