javascript - 如何使我的左侧菜单栏在单击时显示和隐藏更改图标

标签 javascript html css django-templates

您好,我知道这个问题被问过很多次,我尝试了很多解决方案,但对我来说都行不通。因此我想发布这个问题寻求帮助。 我有一个 django 应用程序,它有一些在 bootstrap 的帮助下完成的 html 模板。现在我希望其中一个 div 完全隐藏(当它被隐藏时,一个图标应该出现在侧边栏的位置)并在单击图标时显示左侧菜单栏。 这是我的 html 文件

{% load staticfiles %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
  <title>**</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="{% static 'bootstrap/css/bootstrap.min.css' %}" rel="stylesheet" media="screen">
  <link href="{% static 'bootstrap/css/dashboard.css' %}"  rel="stylesheet">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  <script src="{% static 'bootstrap/js/bootstrap.min.js' %}"></script>
  <link href="{% static 'style.css' %}"  rel="stylesheet">
  <script src='http://codepen.io/assets/libs/fullpage/jquery.js'></script>
   
</head>
<body>
{% block content %}
<nav class="navbar navbar-inverse navbar-fixed-top">
  <div class="container-fluid">
    
    <div class="navbar-header">
      <a class="navbar-brand" href="http://www.google.com/"><img src="{% static "bootstrap/css/logo4.png" %}" alt="MPOWER" style="margin-top:-5%;"/></a>
    </div>

    <div>
      <ul class="nav navbar-nav navbar-right">
<li></li>
        <li><a href="#"><span class="glyphicon glyphicon-user"></span> {% if user.is_authenticated %}

        {{ user.first_name }}
       {{ request.user.username }}</a></li>
{% endif %}
        <li><a href="{% url 'django.contrib.auth.views.logout' %}"><span class="glyphicon glyphicon-log-out\"></span>Logout</a></li>

      </ul>

    </div>
  </div>
</nav>

<div class="container-fluid" >
<div id="overlay"></div>
<div class="row">
        <div class="col-sm-3 col-md-2 sidebar" id="mobile-menu">
          <ul class="nav nav-sidebar">
<li><a href="#"><span id="menu-button"><span class="glyphicon glyphicon-chevron-right"></span></span></a></li>
        <li><span style="color:blue; font-weight:bold;">Dashboardsssss</span></li>     
	 {% for Dashboard in dashboards %}
<li><a href="{{ Dashboard.d_url }}" target="iframe_a">{{ Dashboard.d_name }}</a></li>
           {% endfor %}
          </ul>
          
        </div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" style="height:600px; margin-top:4%;">


<iframe width="100%"  height="95%" name="iframe_a" frameborder="0"></iframe>

</div>


   </div>

</div>



<script src='http://codepen.io/assets/libs/fullpage/jquery.js'></script>

  <script src="{% static 'index.js' %}"></script>
{% endblock %}



</body>
</html

在上面的 html 页面中,我希望这个 div 在每次点击时显示和隐藏,并且它应该在同一菜单栏上有一个图标来执行此操作。 注意:图标应该始终可见。 请帮我做这个功能。 提前致谢。 CSS 看起来像

#main_header .panel_btn	{
	display: block;
	position: absolute;
	left: 15px;
	top: 15px;
	height: 20px;
	width: 20px;
	background: rgb(200,200,200);
	z-index: 5;
}

#main_header .panel_btn .line	{
	display: block;
	position: relative;
	height: 4px;
	margin-bottom: 4px;
	background: rgb(80,80,80);
}
#main_header .panel_btn .line:last-child	{
	margin-bottom: 0px;
}


.navbar-fixed-top {
  border: 0;
}

/*
 * Sidebar
 */

/* Hide for mobile, show later */
.sidebar {
  display: none;
  
}
@media (min-width: 768px) {
  .sidebar {
    position: fixed;
    top: 51px;
    bottom: 0;
    left: 0;
    z-index: 1000;
    display: block;
    padding: 20px;
    overflow-x: hidden;
    overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
    background-color: #f5f5f5;
    
          }
}

/* Sidebar navigation */
.nav-sidebar {
  margin-right: -21px; /* 20px padding + 1px border */
  margin-bottom: 20px;
  margin-left: -20px;
  
}
.nav-sidebar > li > a {
  padding-right: 20px;
  padding-left: 20px;
}
.nav-sidebar > .active > a,
.nav-sidebar > .active > a:hover,
.nav-sidebar > .active > a:focus {
  color: #fff;
  background-color: #428bca;
}


/*
 * Main content

 */

最佳答案

我想您需要折叠的导航栏。有关于它的信息:http://getbootstrap.com/components/#navbar

关于javascript - 如何使我的左侧菜单栏在单击时显示和隐藏更改图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29508977/

相关文章:

javascript - 如果选中复选框,则使用欺骗按钮继续下一页

javascript - 删除 JavaScript 中的元素

jquery - 在 jQuery 中创建 img

javascript - 将 JavaScript 年龄计算返回到屏幕

jquery - 悬停效果在 IE 浏览器中无法正常工作

javascript - Chrome 应用的应用内数据

javascript - 设置日期选择器开始日期 jQuery

html - Bootstrap 导航栏显示

html - CSS 样式表在 IE 上部分加载

javascript - Angular-UI-Router 模态像 pinterest