javascript - Overlay fixed on top of div and keep position page scrolled -


i've following example below. when click yellow box, overlay shown , works fine. when scroll down ofc stays because has position fixed.

how can make sure overlay stay ontop of .div when scroll, aka "don't move"?

$('.modal').css("top", $(".div").offset().top).css("left", $(".div").offset().left).css("width", $(".div").css("width")).css("height", $(".div").css("height"));    $(".div").click(function() {    $('.modal').addclass("loading");  })
.div {    margin-top: 100px;    margin-left: auto;    margin-right: auto;    height: 300px;    width: 300px;    background-color: yellow;    content: "";  }    body {    height: 500px;    background-color:black;  }    .modal {    display: none;    position: fixed;    z-index: 1000;    top: 0;    left: 0;    height: 100%;    width: 100%;    background: rgba( 255, 255, 255, .8) url('http://sampsonresume.com/labs/pikfp.gif') 50% 50% no-repeat;  }    .modal.loading {    display: block;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="div"></div>  <div class="modal"></div>

change position absolute.

.modal {   display: none;   position: absolute;   z-index: 1000;   top: 0;   left: 0;   height: 100%;   width: 100%;   background: rgba( 255, 255, 255, .8) url('http://sampsonresume.com/labs/pikfp.gif') 50% 50% no-repeat; } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -