我的滑入式菜单仍然存在问题。据我所知,一切都还可以,但是当用户向下滚动并通过汉堡包图标打开菜单时,由于滚动也是导航,因此导航无法查看。 所以我需要的是使navi变得粘稠。但是当我改变位置(类:nav)来自绝对的'要修复',导航超出我的最大宽度(如果屏幕大小>最大宽度)。
$(document).ready(function(){
$('input:checkbox').change(function(){
if($(this).is(":checked")) {
$(".content").animate({ left: '-200px' });
$(".content").css({"box-shadow": "0 0 5px 5px rgba(0,0,0,0.5)" });
} else {
$(".content").animate({ left: '0' });
$(".content").css({"box-shadow": "none" });
}
});
});

body {
background-color:red;
}
h1 {
padding: 10px 0 20px 0;
font-size: 1.7em;
}
p {
padding-bottom: 20px;
line-height: 18px;
}
.wrp {
position:relative;
max-width: 1200px;
margin: 0px auto;
padding:0 20px;
height:100%;
background-color:orange;
}
.header {
position:fixed;
top:0;
width:100%;
background-color: white;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
z-index:1000000;
}
.logo {
float:left;
width: 200px;
border:solid red 1px;
}
.menu {
float:right;
border:solid black 1px;
position:relative;
}
.content2 {
padding:5px 10px;
background-color:blue;
color:white;
position: relative;
top: 0;
bottom: 100%;
left: 0;
}
.content {
/* Critical position and size styles */
min-height: 100%;
min-width: 100%;
position: relative;
top: 0;
bottom: 100%;
left: 0;
z-index: 1;
background-color:blue; /* Needs a background or else the nav will show through */
/* non-critical apperance styles */
background-size: 200%;
opacity: 0.5;
transition: right 0.5s;
}
.nav {
position:absolute;
width: 200px;
top: 0;
right: 0;
bottom: 0;
padding-top: 50px;
background-color:green;
opacity: 0.5;
}
/* hb icon */
.menu-icon {
padding: 18px 14px; /* better clickable > please consider in header */
cursor: pointer;
display: inline-block;
float: right;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
}
.menu-icon .navicon {
background: #333;
display: block;
height: 2px;
position: relative;
width: 18px;
}
.menu-icon .navicon:before,
.menu-icon .navicon:after {
background: #333;
content: '';
display: block;
height: 100%;
position: absolute;
transition: all .2s ease-out;
width: 100%;
}
.menu-icon .navicon:before {
top: 5px;
}
.menu-icon .navicon:after {
top: -5px;
}
/* Nav Trigger */
.nav-trigger {
/* critical styles - hide the checkbox input */
position: absolute;
clip: rect(0, 0, 0, 0);
}
label[for="nav-trigger"] {
/* critical positioning styles */
right: 15px;
top:0;
z-index: 3;
}
.nav-trigger:checked ~ .menu-icon .navicon {
background: transparent;
}
.nav-trigger:checked ~ .menu-icon .navicon:before {
transform: rotate(-45deg);
}
.nav-trigger:checked ~ .menu-icon .navicon:after {
transform: rotate(45deg);
}
.nav-trigger:checked ~ .menu-icon:not(.steps) .navicon:before,
.nav-trigger:checked ~ .menu-icon:not(.steps) .navicon:after {
top: 0;
}
/* Make the Magic Happen */
.nav-trigger + label, .wrp {
transition: left 0.5s;
}
.nav-trigger + label {
right: 15px;
transition: right 0.5s;
}
.nav-trigger:checked + label {
right: 215px;
}
.nav-trigger:checked ~ .nav {
border: 4px solid red;
}
.nav-trigger:checked ~ .content {
left: -200px;
box-shadow: 0 0 5px 5px rgba(0,0,0,0.5);
background-color:red;
}

<link href="http://yui.yahooapis.com/3.18.1/build/cssreset/cssreset-min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="header">
<div class="wrp">
<div class="logo">Logo</div>
<div class="menu">
<input type="checkbox" class="nav-trigger" id="nav-trigger" />
<label for="nav-trigger" class="menu-icon"><span class="navicon"></span></label>
</div>
<div style="clear:both;"></div>
</div>
</div>
<div class="wrp">
<div class="content">
<h1>This is my content</h1>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
</div>
<div class="nav">
<h1>Navi</h1>
</div>
</div>
&#13;
Codepen上的守则:http://codepen.io/anon/pen/NxeLzY
有人可以帮忙吗?
答案 0 :(得分:1)
在导航容器内放置一个子容器,例如:
<div class="nav">
<div class="nav-child">
<h1>Navi</h1>
</div>
</div>
然后设置样式以便修复子容器:
.nav-child{
position:fixed;
}
请参阅此处获取codepen解决方案:
答案 1 :(得分:0)
试试这个: 在HTML替换:
<div class="nav">
<div class="inner_nav">
<h1>Navi</h1>
</div>
</div>
在CSS中添加:
.inner_nav
{
position:fixed;
}