1

Tried the solution here, does not work.

Prevent BODY from scrolling when a modal is opened

The modal is here:

<style>
    /* The Modal (background) */
    .modal {
        display: none; /* Hidden by default */
        position: fixed; /* Stay in place */
        z-index: 9999; /* Sit on top */
        left: 0px;
        top: 0px;
        width: 100%; /* Full width */
        height: 100%; /* Full height */
        overflow: auto; /* Enable scroll if needed */
        background-color: rgb(0,0,0); /* Fallback color */
        background-color: rgba(0,0,0,0.6); /* Black w/ opacity */
    }

    /* Do not remove - Prevents android from jumping to top */
    body.modal-open {
        overflow: visible;
        position: fixed;
        width: 100%;
        height:100%;
    }

    /* Modal Content/Box */
    .modal-content {
        background-color: #fefefe;
        margin: 30% auto; /* 30% from the top and centered */
        padding: 0px;
        overflow-y:auto;
        border-radius: 10px;
        border: 0px;
        max-height:70%;
        width: 80%; /* Could be more or less, depending on screen size */
    }

    /* Modal Content/Box */
    .modal-image-content {
        z-index: 99999; /* Sit on top */
        padding: 0px;
        margin: auto; /*centered */
        border: 0px;
        max-height:100%;
        max-width:100%;
    }

    /* Links inside the dropdown */
    .modal-content a {
        color: black;
        padding: 10px;
        text-decoration: none;
        display: block;
    }

    /* Links inside the dropdown */
    .modal-content a:hover{
        background-color: #dddddd;
    }

    /* The Close Button */
    .close {
        color: #aaa;
        float: right;
        font-size: 28px;
        font-weight: bold;
    }

    .close:hover,
    .close:focus {
        color: black;
        text-decoration: none;
        cursor: pointer;
    }
</style>

As you can see, the body.modal-open thing was taken from the solution but it does not work.

Again, how to make the modal stop making the screen scroll to the top?

Community
  • 1
  • 1
theAnonymous
  • 1,701
  • 2
  • 28
  • 62

1 Answers1

1

This thing is weird as heck, my Google-fu skills solved it.

Change <a href="#" ...

To <a href="javascript: void(0);" ...

theAnonymous
  • 1,701
  • 2
  • 28
  • 62