我试图切换课程' show'在ul
,以便它显示/隐藏菜单,但我的JQuery不是很好,我似乎无法让它工作
<nav>
<ul class="show">
<li><a href="#sec01">about us</a></li>
<li><a href="#sec02">how it works</a></li>
<li><a href="#sec03">comments</a></li>
</ul>
</nav>
<div class="hamburger"></div>
nav {position:relative; z-index:999; display:flex; height:70px; width:100%; background:none; @include centerer; font-weight:bold;font-family: 'Roboto', sans-serif;
@include small{background:#DADADA;}
@include xs {background:#DADADA;;}}
nav ul {display:flex; list-style:none; flex-direction:row;
@include small{margin-top:160px;flex-direction:column;}
@include xs{flex-direction:column;}}
nav li { padding:20px; text-transform: uppercase;
@include small{background:#fff; color:#000}
@include xs{background:#fff; color:#000;}}
nav li:hover a {border-bottom:2px solid #ff0000;}
nav a,nav a:visited { color:#fff;text-decoration: none;}
nav a:hover,nav a:active {color:#fff; text-decoration: none; ; }
.show{
visibility:hidden;
}
.hamburger{position:absolute; z-index:999;top:10px; right:10px; height:50px; width:70px; background:#000;
https://jsfiddle.net/hsaw3frL/
$(document).ready(function(){
$( ".hamburger" ).click(function() {
$('ul' ).toggleClass( "show" );
});
});
答案 0 :(得分:1)
试一试!
$(document).ready(function(){
$(".hamburger").click(function() {
$("ul").toggleClass("show");
});
})
答案 1 :(得分:1)
有很多方法可以实现您的目标。
修复类的选择,添加新的css属性.hide
,修改/更新ul
元素,方法是给它一个id(你不想隐藏所有ul
个元素)
html
<ul id='menubar' class="show">
脚本
$(document).ready(function() {
$(".hamburger").click(function() {
$('#menubar').toggleClass("hide");//toggle this class
});
});
CSS
.hide{
display: none !important;
}