0

At the top and bottom of the visible area of the jQueryUI dialog I have divs, represented by the gray boxes, the .nav elements in the snippet, and I want them to remain in a fixed position when you scroll within the dialog. I set position: absolute for the gray boxes, yet they still scroll with the rest of the content in the dialog. How can I keep them at a fixed position within the dialog?

$(document).ready(function() {
 var opts = {
   modal: true,
    height:300,
  };
  
  $('#wrapper').dialog(opts);
  $('#wrapper').dialog('open');

});
.images {
  z-index: 1;
}

.image {
  display: inline-block;
  border: 1px solid black;
  width: 100%;
  height: 500px;
}

.nav {
  width: 90%;
  height: 30px;
  z-index: 2;
  background-color: rgba(192, 192, 192, 0.7);
  position: absolute;
}

.top {
  top: 0px;
}

.bottom {
  bottom: 0px;
}
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>

<div id='wrapper'>
  <div class='top nav'>
  </div>

  <div class='bottom nav'>
  </div>

  <div class='images'>
    <div class='image'>
    </div>

    <div class='image'>
    </div>

    <div class='image'>
    </div>
  </div>

</div>
user2233706
  • 6,148
  • 5
  • 44
  • 86

1 Answers1

0

Add the following inline style to your wrapper and regulate top to position top nav correctly:

<div id='wrapper' style='position: static;'>

and:

.top {
  top: 45px;
}

$(document).ready(function() {
 var opts = {
   modal: true,
    height:300,
  };
  
  $('#wrapper').dialog(opts);
  $('#wrapper').dialog('open');

});
.images {
  z-index: 1;
}

.image {
  display: inline-block;
  border: 1px solid black;
  width: 100%;
  height: 500px;
}

.nav {
  width: 90%;
  height: 30px;
  z-index: 2;
  background-color: rgba(192, 192, 192, 0.7);
  position: absolute;
}

.top {
  top: 45px;
}

.bottom {
  bottom: 0px;
}
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>

<div id='wrapper' style='position: static'>
  <div class='top nav'>
  </div>

  <div class='bottom nav'>
  </div>

  <div class='images'>
    <div class='image'>
    </div>

    <div class='image'>
    </div>

    <div class='image'>
    </div>
  </div>

</div>
dNitro
  • 5,145
  • 2
  • 20
  • 45