当我向下滚动时,如何修复我的sidenav
身体滚动时我的sidenav
底部变空了
问问题
72 次
1 回答
0
var header = $("#menu");
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >0) {
header.addClass("fixed");
} else {
header.removeClass("fixed");
}
});
.fixed{
position: fixed !important;
}
.c {
height: 100vh;
position: relative;
padding: 50px;
}
div#menu {
position: absolute;
padding: 20px;
background: #2196F3;
color: ghostwhite;
width: 200px;
z-index: 1;
height: 100vh;
}
.c {
height: 100vh;
padding: 50px;
margin-left: 300px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="width: 100%">
<div class="nav" id="menu">
<h2>Menu</h2>
</div>
<div class="c">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
于 2018-10-01T08:28:35.773 回答