我不知道发生了什么,但如果有人能帮助我,那可能会很棒。所以我正在尝试为移动布局创建一个离开画布的导航菜单,但我一直在遇到问题;而我现在已经走到了尽头。如果有人可以看看我的代码,并指出我的方向很好。
html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="../scripts/javascript/mobilnavprotoscript.js"></script>
<script src="../scripts/javascript/modernizr.custom.64630.js"></script>
<link href="../css/mobilnavstyles.css" rel="stylesheet" type="text/css" media="screen"/>
<title>Welcome to My Domain</title>
</head>
<body>
<nav id="toggle" class="main">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Video</a></li>
<li><a href="#">Pictures</a></li>
<li><a href="#">Audio</a></li>
<li><a href="#">Other Work</a></li>
<li><a href="#">About Me</a></li>
<li><a href="#">Contact Me</a></li>
</ul>
</nav>
<div id="wrapper">
<div class="mobilmenu"><a href="#toggle" class="nav-link"><i class="fa fa-bars"></i></a></div>
<header>
<h1>This is a placeholder <br />
for header</h1>
</header>
<div id="content">
<article class="content-main">
<section>
<h2>Heading goes here...</h2>
<time datetime="2014-05-21T02:43:00">Officialy Posted On May 21<sup>st</sup> 2:35 A.M.</time>
<p>Content will go here...</p>
</section>
</article>
<aside>
<p>More content soon...</p>
</aside>
</div>
<footer>
<div class="copyright">
<span>All rights reserved 2014.</span>
</div>
<nav class="foot">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Video</a></li>
<li><a href="#">Pictures</a></li>
<li><a href="#">Audio</a></li>
<li><a href="#">Other Work</a></li>
<li><a href="#">About Me</a></li>
<li><a href="#">Contact Me</a></li>
</ul>
</nav>
</footer>
</div>
</body>
</html>
这是我想要做的事情的必要条件(请告诉我,如果我需要查看我的css的任何其他部分。):
nav#toggle
{
position: absolute;
top: 0;
bottom: 0;
width: 15.750em;
left: -15.750em;
transform: translate(0px, 0px);
transition: 0.15s ease;
height: 100%;
}
nav#toggle.active
{
transform: translate(15.750em, 0px);
}
nav.main
{
margin: 0;
padding: 0;
font-family: 'bebas_neueregular',sans-serif;
box-shadow: 0px 2px 3px #393333;
background-color: #950707;
}
nav.main ul
{
display: flex;
flex-direction: column;
text-align: right;
font-size: 1.45em;
list-style: none;
margin: 0;
padding: 0;
}
nav.main ul li
{
border-bottom: 1px solid #af1b1b;
}
nav.main ul li:first-child
{
border-top: 1px solid #af1b1b;
}
nav.main ul li a
{
display: block;
text-decoration: none;
color: inherit;
padding: 0.35em;
}
nav.main ul li a:hover
{
background-color: #ffffff;
}
div.mobilmenu
{
background-color: #950707;
}
div.mobilmenu a
{
text-decoration: none;
color: inherit;
}
div.mobilmenu a i
{
font-size: 1.75em;
padding: 0.32em;
}
div.mobilmenu a i:hover
{
background-color: #ffffff;
transition: 325ms ease;
}
#wrapper
{
display: flex;
flex-direction: column;
transform: translate(0px, 0px);
transition: 0.15s ease;
}
#wrapper.active
{
transform: translate(15.750em, 0px);
}
这是我正在使用的jQuery脚本:
$(document).ready(function () {
$('a.nav-link').click(function () {
$('nav#toggle').toggleClass('active');
$('#wrapper').toggleClass('active');
});
});
答案 0 :(得分:0)
这是你想要做的吗? http://jsfiddle.net/qsHRh/2/
$(document).ready(function () {
$('a.nav-link').click(function () {
$('nav#toggle').toggleClass('active');
$('#wrapper').toggleClass('active');
});
$('.nav-link').click(function(){
$('#toggle').animate({left:'0px'},200);
});
$(document).click(function(e){
if (!$('#toggle, .nav-link').is(e.target) && $('#toggle').has(e.target).length === 0){
$('#toggle').animate({left:'-15.750em'},200);
}
});
});
更新:
你需要将整个页面包装成div,让它称之为#whole,然后给它样式position:relative; left:0; top:0;
,然后根据需要移动整个页面。检查下面的小提琴:
我认为这就是你所需要的。如果没有,请告诉我。