你甚至可以用CSS做所有這些。但是,讓我們繼續使用js路由:首先將非導航主體內容包裝在絕對定位的包裝中。
![enter image description here](https://i.stack.imgur.com/25dLN.gif)
<body>
<nav>
<ul>
<li><a id="ab" href="#about">About</a>
</li>
<li><a id="po" href="#portfolio">Portfolio</a>
</li>
<li><a id="co" href="#contact">Contact</a>
</li>
<li><a id="bl" href="#blog">Blog</a>
</li>
</ul>
</nav>
<div class="wrapper"> <!-- here -->
<div id="burger">
<img src="https://www.iconfinder.com/icons/134216/hamburger_lines_menu_icon" alt="Munu">
</div>
CSS
div.wrapper {
position: absolute;
width: 100%;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
transition: left 200ms ease;
}
body {
position: relative; // relative class
font: normal 1.1em/1.5 sans-serif;
color: #fff;
font-family:'Raleway', sans-serif;
background-color: black;
}
JS
$(function() {
var navWidth = $('nav').outerWidth(true);
$('#burger, nav').hover(function() {
$('nav').stop().slideDown(200);
$('div.wrapper').css({
'left': navWidth + 'px',
});
}, function() {
$('nav').stop().slideUp(200);
$('div.wrapper').css({
'left': '0px',
});
})
});
即可投入爵士小提琴嗎? – Todd
http://jsfiddle.net/ChilledMonkeyBrain/06ysqr1r/ – chilledMonkeyBrain