javascript - How to disable background div scroll temporary while the front div can still be scrolled? -


i have 2 div, 1 in front , 1 in back. front popup when button pushed. if front div isn't displayed, background div can scrolled. in contrary, if front div displayed, background div scroll disable. front div can still scrolled.

img

i have tried using css applying no-scroll css background div.

.no-scroll {     position: fixed;     overflow: hidden } 

but every time applied no-scroll class element, bounced top top.

i followed this article

but disable entire window scroll , font div too. suggestion?

i think should wrap both divs in container , toggle class on that. this

var btn = document.queryselector('button'),      wrapper = document.queryselector('.wrapper');    btn.addeventlistener('click', function(){    wrapper.classlist.toggle('modal-is-visible');  });
html, body { height: 100% }    .wrapper {     height: 500px;    overflow: scroll;    border: solid 2px black;    padding: 2rem;  }    .lower_div {    background: red;    width: 100%;        height: 600px;    position: relative;  }      .modal {    display: none;    height: 20px;    width: 100%;    position: absolute;    z-index: 2;    background: tomato;  }    .modal-is-visible .modal { display: block;}    .modal-is-visible.wrapper { overflow: hidden; }
<button>  toggle  </button>  <div class="wrapper">    <div class="lower_div">      <div class="modal">      </div>    </div>  </div>


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -