Bootstrap modal: background jumps to top on toggle

后端 未结 30 3114
栀梦
栀梦 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 19:59
    body.modal-open {
    overflow: visible !important;
    }
    

    I needed the important attribute for it to fix it

    0 讨论(0)
  • 2020-11-29 19:59

    If pstenstrm's answer doesn't work for you, try combining it with this replacement button HTML:

    <a class="btn btn-primary btn-lg" data-toggle="modal" data-target="#generalModal" id="launchbutton" href="#launchbutton"> Launch demo modal </a>
    

    This should keep the button on-screen.

    0 讨论(0)
  • 2020-11-29 20:00
    $('the thing you click on').click(function ($e) {
                $e.preventDefault();
    });
    

    This will help you to stop the scroll bar going on the top.It worked for me

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

    I don't see a specific error, but I would advise you to check your html syntax.

    A tiny test with your source gives me errors like

    Line 127, Column 34: Unclosed element div.

                  <div class="inner onlySides">
    

    This could be an issue.

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

    If you are calling modal with tag. Try removing '#' from href attribute.And call modal with data attributes.

    <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
      Launch demo modal
    </button>
    
    0 讨论(0)
  • 2020-11-29 20:02

    height:100% is solve problem, but you must add correct "div"

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