請注意,我
交換在HTML
改變了的CSS的<div class="overlay">
和<div class="viewport">
的順序.overlay
HTML
<div>
<div class="app-bar">
<span class="big">Hello.</span>
<button class="open-overlay">
Open Overlay
</button>
</div>
<div class="overlay">
<button class="close-overlay">
Close this.
</button>
<p>00000</p>
<p>11111</p>
<p>22222</p>
<p>33333</p>
<p>44444</p>
<p>55555</p>
<button class="close-overlay">
Close this.
</button>
</div>
<div class="viewport">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est corporis cum iure id voluptatibus inventore recusandae veniam dolorum harum, minus officia blanditiis asperiores illum laudantium tenetur doloremque hic ea atque!
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corporis illo eligendi magnam laudantium tenetur in consequatur aperiam totam beatae, accusamus sed, distinctio cum quam. Unde dolores ut consectetur temporibus similique.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est corporis cum iure id voluptatibus inventore recusandae veniam dolorum harum, minus officia blanditiis asperiores illum laudantium tenetur doloremque hic ea atque!
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corporis illo eligendi magnam laudantium tenetur in consequatur aperiam totam beatae, accusamus sed, distinctio cum quam. Unde dolores ut consectetur temporibus similique.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est corporis cum iure id voluptatibus inventore recusandae veniam dolorum harum, minus officia blanditiis asperiores illum laudantium tenetur doloremque hic ea atque!
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corporis illo eligendi magnam laudantium tenetur in consequatur aperiam totam beatae, accusamus sed, distinctio cum quam. Unde dolores ut consectetur temporibus similique.
</p>
</div>
</div>
個
CSS
body {
margin: 0;
}
.app-bar {
color: #fff;
min-height: 64px;
background: #999;
position: relative;
}
.big {
font-size: 2em;
}
.viewport {
padding: 1em;
font-size: 18px;
position: absolute;
border: 2px solid blue;
top: 64px;
left: 0;
right: 0;
bottom: 0;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
}
.overlay {
position:relative;
display: none;
top:0;
bottom:0;
left:0;
right:0;
height:calc(100vh - 64px); /* viewport height minus .app-bar height */
background: #fff;
padding: 1em;
z-index: 9000;
}
JS
$('.open-overlay').on('click', function() {
$('.overlay').fadeIn();
});
$('.close-overlay').on('click', function() {
$('.overlay').fadeOut();
});
http://codepen.io/anon/pen/BjJZKB
有一些問題,與固定在移動位置,所以你最好避開使用它。 –
即使我將所有「固定」切換爲「絕對」,問題仍然存在。 – ffxsam
http://codepen.io/pen/也許? –