我已創建了一個粘貼到頁面的側導航欄切換菜單。問題是當我調整我的窗口屏幕時,除非頁面滾動到頂部,否則它不會切換。當窗口大小調整時,Navbar不會切換
HTML
<i class="fa fa-bars fa-2x nav-toggle"></i>
<nav class="main-navigation">
<ul class='nav-links'>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#skills">Skills</a></li>
<li><a href="#portfolio">Portfolio</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
CSS
.main-navigation {
position: fixed;
top:0;
left:0;
width: 100px;
height: 100px;
text-align: center;
transform: translateY(-210%);
transition: transform 0.6s ease;
}
.main-navigation.open {
transform: translateY(50%);
}
JS
$('.nav-toggle').on('click', function(){
$('.main-navigation').toggleClass('open');
});
請提供的jsfiddle。 – Alex
https://jsfiddle.net/7grquucm/ –
你的'.main-navigation'必須有'position:fixed'? – Alex