【发布时间】:2016-02-13 19:20:51
【问题描述】:
我在通过单击导航菜单图标显示导航菜单时遇到了一些问题。
HTML
nav role="navigation" class="navbar">
<div class="nav-header">
<a href="#"><span style="font-family: 'Cabin Sketch', cursive; font-size: 1.4em;">Testy Testy Web</span></a>
<a href="#menu" id="toggle"><span><i class="fa fa-bars"></i></span></a>
</div>
<div id="menu">
<ul>
<li><a href="#about">About</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#pricing">Pricing</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
</nav>
CSS
nav {width: 100%; position: fixed; text-align: left; background-color: #404040; z-index: 999;}
nav ul li {display: inline;}
nav a {text-decoration: none; float: left; color: white; padding: 1em; line-height: 100%;}
nav a:hover {background-color: #1AA2D4;}
.nav-header a {display: inline-block;}
#toggle {float: right; display: none;}
@media (max-width: 592px) {
.splash p {font-size: 1em;}
.splash h1 {font-size: 8em;}
nav {width: 100%; position: fixed; top: 0; text-align: left; background-color: #404040; z-index: 999;}
nav ul li {display: block; float: left; clear: left; width: 100%; clear: bottom;}
nav ul {width: 100%;}
nav a {text-decoration: none; float: left; color: white; padding: 1em; line-height: 100%;}
#toggle {float: right; display: block;}
#menu {display: none;}
JavaScript/jQuery
$(document).ready(function(){
$('#toggle').click(function(){
$('#menu').css('display', 'visible');
});
});
基本上,我有它,以便在较小的屏幕上显示导航链接时隐藏,但是我正在努力弄清楚如何让 jQuery 在单击切换图标时使其可见。我知道这是 Bootstrap 中的标准内容,但我正在构建的网站没有使用框架。
有没有人可以让我知道我做错了什么。
谢谢
【问题讨论】:
-
你试过
$('#menu').show()吗? -
$('#menu').css('display', 'visible'); -- display 没有可见的值 -- 检查这里 -- w3schools.com/cssref/pr_class_display.asp -- 你可以这样做 -- $('#menu').css('display', 'none'); -- 隐藏 -- $('#menu').css('display', ''); -- 显示
标签: javascript jquery html css twitter-bootstrap