简体   繁体   English

可折叠侧边栏/导航菜单

[英]Collapsable sidebar / navigation menu

I'm coding a website, i have a navigation bar on top of it, and a sidebar on the left.我正在编写一个网站,顶部有一个导航栏,左侧有一个侧边栏。 I want to turn this Fiddle into this one .我希望把这个小提琴到这个一个 It can use CSS, JQuery, JavaScript and Bootstrap, when you click the icon, the sidebar drags out to the right.它可以使用 CSS、JQuery、JavaScript 和 Bootstrap,当您单击图标时,侧边栏会向右拖出。 And when you click it again, it collapse to the left.当您再次单击它时,它会向左折叠。

<ul id="navbar">
  <li class="title" id="sidebar_switch"><i class="fa fa-bars" aria-     hidden="true"></i></li>
  <li class="title"><img alt="Logo" src="http://www.iconsdb.com/icons/preview/orange/stackoverflow-6-xxl.png" height="16px" width="16px"></li>
  <li class="title">Title</li>
</ul>

please have a look at the following solution based on your code using CSS3 translate :请根据您的代码使用 CSS3 translate查看以下解决方案:

HTML: HTML:

 <div class="sidebar">
   <p>
     This sidebar goes all screen down, and if you scroll the webpage, the sidebar stays at the same place everytime, the scro
   </p>
</div>
<div class="content">
  <ul id="navbar">
  <li class="title" id="sidebar_switch"><i class="fa fa-bars" aria-hidden="true"></i></li>
  <li class="title"><img alt="Logo" src="http://www.iconsdb.com/icons/preview/orange/stackoverflow-6-xxl.png" height="16px" width="16px"></li>
  <li class="title">Title</li>
</ul>
  <div class="main">
    aaaaaaaaaa
  </div>
</div>

CSS: CSS:

  body {
  height: 100%;
  width: 100%;
  margin: 0px;
  font-family: sans-serif;
  overflow: hidden;
}

a {
  text-decoration: none;
}

.title {
  float: left;
  display: block;
  padding: 14px 16px;
}

#navbar {
  font-weight: bold;
  text-align: center;
  float: left;
  background-color: #333;
  color: white;
  list-style-type: none;
  overflow: hidden;
  margin: 0;
  padding: 0;
  width: 100%;
}

.sidebar{
  position:fixed;
  top:0px;
  left:0px;
  width:100%;
  color:red;

}

.slide{
    -webkit-transform: translate3d(25%,0,0);
}

.content{
  width:100%;
  height: 30em;
  position:absolute;
  left:0px;
  top:0px;
  background: white;
  -webkit-transition:all .2s linear;
}

.content .slide{
    -webkit-transform: translate3d(25%,0,0);
}

i{
  cursor: pointer;
}

JS: JS:

$('i').click(function(){
    $('.content').toggleClass('slide');
});

JS Fiddle Demo JS小提琴演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM