我試圖找到一個很好的模板或部分代碼,把自己在這個網站上找到相同的菜單:引導離開可摺疊導航菜單
我需要的菜單從左側顯示屏幕的其餘部分會稍微變暗,就像在我找到的網站中一樣。
有沒有簡單的方法來應用這樣做的引導模板?或者,也許會很方便地開始從頭開始編碼導航欄部分?
感謝,
我試圖找到一個很好的模板或部分代碼,把自己在這個網站上找到相同的菜單:引導離開可摺疊導航菜單
我需要的菜單從左側顯示屏幕的其餘部分會稍微變暗,就像在我找到的網站中一樣。
有沒有簡單的方法來應用這樣做的引導模板?或者,也許會很方便地開始從頭開始編碼導航欄部分?
感謝,
這從Bootsnipp演示可能爲你工作。調整下面的示例代碼片段。
$(document).ready(function() {
var trigger = $('.hamburger'),
overlay = $('.overlay'),
isClosed = false;
trigger.click(function() {
hamburger_cross();
});
function hamburger_cross() {
if (isClosed == true) {
overlay.hide();
trigger.removeClass('is-open');
trigger.addClass('is-closed');
isClosed = false;
} else {
overlay.show();
trigger.removeClass('is-closed');
trigger.addClass('is-open');
isClosed = true;
}
}
$('[data-toggle="offcanvas"]').click(function() {
$('#wrapper').toggleClass('toggled');
});
});
body {
position: relative;
overflow-x: hidden;
}
body,
html {
height: 100%;
}
.nav .open > a,
.nav .open > a:hover,
.nav .open > a:focus {
background-color: transparent;
}
/*-------------------------------*/
/* Wrappers */
/*-------------------------------*/
#wrapper {
padding-left: 0;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#wrapper.toggled {
padding-left: 220px;
}
#sidebar-wrapper {
z-index: 1000;
left: 220px;
width: 0;
height: 100%;
margin-left: -220px;
overflow-y: auto;
overflow-x: hidden;
background: #1a1a1a;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#sidebar-wrapper::-webkit-scrollbar {
display: none;
}
#wrapper.toggled #sidebar-wrapper {
width: 220px;
}
#page-content-wrapper {
width: 100%;
padding-top: 70px;
}
#wrapper.toggled #page-content-wrapper {
position: absolute;
margin-right: -220px;
}
/*-------------------------------*/
/* Sidebar nav styles */
/*-------------------------------*/
.navbar .sidebar-nav {
position: absolute;
top: 0;
width: 220px;
margin: 0;
padding: 0;
list-style: none;
}
.navbar .sidebar-nav li {
position: relative;
line-height: 20px;
display: inline-block;
width: 100%;
}
.navbar .sidebar-nav li:before {
content: '';
position: absolute;
top: 0;
left: 0;
z-index: -1;
height: 100%;
width: 3px;
background-color: #1c1c1c;
-webkit-transition: width .2s ease-in;
-moz-transition: width .2s ease-in;
-ms-transition: width .2s ease-in;
transition: width .2s ease-in;
}
.navbar .sidebar-nav li:hover:before,
.navbar .sidebar-nav li.open:hover:before {
width: 100%;
-webkit-transition: width .2s ease-in;
-moz-transition: width .2s ease-in;
-ms-transition: width .2s ease-in;
transition: width .2s ease-in;
}
.navbar .sidebar-nav li a {
display: block;
color: #ddd;
text-decoration: none;
padding: 10px 15px 10px 30px;
}
.navbar .sidebar-nav li a:hover,
.navbar .sidebar-nav li a:active,
.navbar .sidebar-nav li a:focus,
.navbar .sidebar-nav li.open a:hover,
.navbar .sidebar-nav li.open a:active,
.navbar .sidebar-nav li.open a:focus {
color: #fff;
text-decoration: none;
background-color: transparent;
}
.navbar .sidebar-nav > .sidebar-brand {
height: 65px;
font-size: 20px;
line-height: 44px;
}
.navbar .sidebar-nav .dropdown-menu {
position: relative;
width: 100%;
padding: 0;
margin: 0;
border-radius: 0;
border: none;
background-color: #222;
box-shadow: none;
}
/*-------------------------------*/
/* Hamburger-Cross */
/*-------------------------------*/
.hamburger {
position: fixed;
top: 20px;
z-index: 999;
display: block;
width: 32px;
height: 32px;
margin-left: 15px;
background: transparent;
border: none;
}
.hamburger:hover,
.hamburger:focus,
.hamburger:active {
outline: none;
}
.hamburger.is-closed:before {
content: '';
display: block;
width: 100px;
font-size: 14px;
color: #fff;
line-height: 32px;
text-align: center;
opacity: 0;
-webkit-transform: translate3d(0, 0, 0);
-webkit-transition: all .35s ease-in-out;
}
.hamburger.is-closed:hover:before {
opacity: 1;
display: block;
-webkit-transform: translate3d(-100px, 0, 0);
-webkit-transition: all .35s ease-in-out;
}
.hamburger.is-closed .hamb-top,
.hamburger.is-closed .hamb-middle,
.hamburger.is-closed .hamb-bottom,
.hamburger.is-open .hamb-top,
.hamburger.is-open .hamb-middle,
.hamburger.is-open .hamb-bottom {
position: absolute;
left: 0;
height: 4px;
width: 100%;
}
.hamburger.is-closed .hamb-top,
.hamburger.is-closed .hamb-middle,
.hamburger.is-closed .hamb-bottom {
background-color: #1a1a1a;
}
.hamburger.is-closed .hamb-top {
top: 5px;
-webkit-transition: all .35s ease-in-out;
}
.hamburger.is-closed .hamb-middle {
top: 50%;
margin-top: -2px;
}
.hamburger.is-closed .hamb-bottom {
bottom: 5px;
-webkit-transition: all .35s ease-in-out;
}
.hamburger.is-closed:hover .hamb-top {
top: 0;
-webkit-transition: all .35s ease-in-out;
}
.hamburger.is-closed:hover .hamb-bottom {
bottom: 0;
-webkit-transition: all .35s ease-in-out;
}
.hamburger.is-open .hamb-top,
.hamburger.is-open .hamb-middle,
.hamburger.is-open .hamb-bottom {
background-color: #1a1a1a;
}
.hamburger.is-open .hamb-top,
.hamburger.is-open .hamb-bottom {
top: 50%;
margin-top: -2px;
}
.hamburger.is-open .hamb-top {
-webkit-transform: rotate(45deg);
-webkit-transition: -webkit-transform .2s cubic-bezier(.73, 1, .28, .08);
}
.hamburger.is-open .hamb-middle {
display: none;
}
.hamburger.is-open .hamb-bottom {
-webkit-transform: rotate(-45deg);
-webkit-transition: -webkit-transform .2s cubic-bezier(.73, 1, .28, .08);
}
.hamburger.is-open:before {
content: '';
display: block;
width: 100px;
font-size: 14px;
color: #fff;
line-height: 32px;
text-align: center;
opacity: 0;
-webkit-transform: translate3d(0, 0, 0);
-webkit-transition: all .35s ease-in-out;
}
.hamburger.is-open:hover:before {
opacity: 1;
display: block;
-webkit-transform: translate3d(-100px, 0, 0);
-webkit-transition: all .35s ease-in-out;
}
/*-------------------------------*/
/* Overlay */
/*-------------------------------*/
.overlay {
position: fixed;
display: none;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, .4);
z-index: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div id="wrapper">
<div class="overlay"></div>
<!-- Sidebar -->
<nav class="navbar navbar-inverse navbar-fixed-top" id="sidebar-wrapper" role="navigation">
<ul class="nav sidebar-nav">
<li class="sidebar-brand"> <a href="#">
Brand
</a>
</li>
<li> <a href="#">Home</a>
</li>
<li> <a href="#">About</a>
</li>
<li> <a href="#">Events</a>
</li>
<li> <a href="#">Team</a>
</li>
<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Works <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li class="dropdown-header">Dropdown heading</li>
<li><a href="#">Action</a>
</li>
<li><a href="#">Another action</a>
</li>
<li><a href="#">Something else here</a>
</li>
<li><a href="#">Separated link</a>
</li>
<li><a href="#">One more separated link</a>
</li>
</ul>
</li>
<li> <a href="#">Services</a>
</li>
<li> <a href="#">Contact</a>
</li>
<li> <a href="https://twitter.com/maridlcrmn">Follow me</a>
</li>
</ul>
</nav>
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="page-content-wrapper">
<button type="button" class="hamburger is-closed" data-toggle="offcanvas"> <span class="hamb-top"></span>
<span class="hamb-middle"></span>
<span class="hamb-bottom"></span>
</button>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<h1>Fancy Toggle Sidebar Navigation</h1>
<p>Bacon ipsum dolor sit amet tri-tip shoulder tenderloin shankle. Bresaola tail pancetta ball tip doner meatloaf corned beef. Kevin pastrami tri-tip prosciutto ham hock pork belly bacon pork loin salami pork chop shank corned beef tenderloin meatball
cow. Pork bresaola meatloaf tongue, landjaeger tail andouille strip steak tenderloin sausage chicken tri-tip. Pastrami tri-tip kielbasa sausage porchetta pig sirloin boudin rump meatball andouille chuck tenderloin biltong shank</p>
<p>Pig meatloaf bresaola, spare ribs venison short loin rump pork loin drumstick jowl meatball brisket. Landjaeger chicken fatback pork loin doner sirloin cow short ribs hamburger shoulder salami pastrami. Pork swine beef ribs t-bone flank filet
mignon, ground round tongue. Tri-tip cow turducken shank beef shoulder bresaola tongue flank leberkas ball tip.</p>
<p>Filet mignon brisket pancetta fatback short ribs short loin prosciutto jowl turducken biltong kevin pork chop pork beef ribs bresaola. Tongue beef ribs pastrami boudin. Chicken bresaola kielbasa strip steak biltong. Corned beef pork loin cow
pig short ribs boudin bacon pork belly chicken andouille. Filet mignon flank turkey tongue. Turkey ball tip kielbasa pastrami flank tri-tip t-bone kevin landjaeger capicola tail fatback pork loin beef jerky.</p>
<p>Chicken ham hock shankle, strip steak ground round meatball pork belly jowl pancetta sausage spare ribs. Pork loin cow salami pork belly. Tri-tip pork loin sausage jerky prosciutto t-bone bresaola frankfurter sirloin pork chop ribeye corned
beef chuck. Short loin hamburger tenderloin, landjaeger venison porchetta strip steak turducken pancetta beef cow leberkas sausage beef ribs. Shoulder ham jerky kielbasa. Pig doner short loin pork chop. Short ribs frankfurter rump meatloaf.</p>
<p>Filet mignon biltong chuck pork belly, corned beef ground round ribeye short loin rump swine. Hamburger drumstick turkey, shank rump biltong pork loin jowl sausage chicken. Rump pork belly fatback ball tip swine doner pig. Salami jerky cow,
boudin pork chop sausage tongue andouille turkey.</p>
</div>
</div>
</div>
</div>
<!-- /#page-content-wrapper -->
</div>
<!-- /#wrapper -->
你爲什麼不使用jQuery插件側面菜單?
http://www.berriart.com/sidr/將滿足您的需求。
讓屏幕的其餘部分變黑也是一個簡單的jQuery技巧。下面的答案將幫助你解決這個問題。
我剛開始做類似的事情。我沒有使用疊加來實現模式效果,但這不應該難以實現。只要看看這個例子,我相信你會明白這個想法。可能是一個很好的起點,但同樣的事情可能以許多不同的方式實現。
var $navbarToggle = $('.navbar-toggle'),
$flyoutContainer = $('.navbar-flyout-container'),
$flyoutDropdownItem = $('.flyout-dropdown-item');
function openFlyout (evt) {
$(this).toggleClass('navbar-toggle-open');
$flyoutContainer.toggleClass('navbar-flyout-open');
}
function openDropdownNavList (evt) {
$(this).find('.flyout-dropdown-container').toggleClass('flyout-dropdown-open');
}
$navbarToggle.on('click', openFlyout);
$flyoutDropdownItem.on('click', openDropdownNavList);
@import url("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css");
html {
min-height: 100%;
position: relative;
}
body {
padding-top: 70px;
}
/* Navbar Toggle Button
-----------------------------------------------------*/
.navbar-toggle {
border-radius: 0;
float: left;
margin: 8px 0 8px 15px;
padding: 0;
width: 44px;
height: 34px;
border-width: 0;
-webkit-transition: margin 0.21s ease-in;
transition: margin 0.21s ease-in;
}
.navbar-toggle-open {
margin: 8px 0 8px 261px;
}
.navbar-toggle .icon-bar {
position: absolute;
top: 9px;
left: 8px;
height: 3px;
width: 26px;
-webkit-transition: top 0.15s ease;
transition: top 0.15s ease;
}
.navbar-toggle .icon-bar+.icon-bar {
margin: 0;
}
.navbar-toggle > .icon-bar:nth-last-child(2) {
top: 15px;
}
.navbar-toggle > .icon-bar:nth-last-child(3) {
top: 21px;
}
/* Navbar Toggle Button Hover
-----------------------------------------------------*/
.navbar-default .navbar-toggle:hover,
.navbar-default .navbar-toggle:focus {
background-color: transparent;
}
.navbar-toggle:hover .icon-bar:last-child {
top: 7px;
}
.navbar-toggle:hover .icon-bar:nth-last-child(3) {
top: 23px;
}
/* Navbar Flyout
-----------------------------------------------------*/
.navbar-flyout-container {
position: absolute;
height: 100%;
top: 0;
left: -360px;
border-right: 1px solid #ccc;
padding: 51px 0 25px; /* top padding height of .navbar-default and bottom-padding */
background: gray;
-webkit-transition: left 0.2s ease-in;
transition: left 0.2s ease-in;
}
.navbar-flyout-open {
left: 0;
}
.navbar-flyout-container .navbar-flyout {
width: 320px;
max-width: 320px;
height: inherit;
padding-bottom: 64px; /* remove the height of .navbar-flyout-header from the bottom */
}
.navbar-flyout .navbar-flyout-header {
width: inherit;
height: 64px;
background-color: transparent;
}
.navbar-flyout .navlist {
list-style-type: none;
overflow-y: auto;
overflow-x: hidden;
padding: 0;
margin: 0;
height: 100%;
background: white;
}
.navbar-flyout .navlist li {
border-top: 1px solid #ccc;
cursor: pointer;
line-height: 48px;
}
.navbar-flyout .navlist li:last-child {
border-bottom: 1px solid #ccc;
}
.navbar-flyout .navlist li a {
display: block;
height: inherit;
white-space: nowrap;
text-overflow: ellipsis;
width: 100%;
overflow-x: hidden;
padding: 0 0 0 6px;
}
.navbar-flyout .navlist li a:hover {
text-decoration: none;
}
/* Flyout Dropdown
-----------------------------------------------------*/
.flyout-dropdown-container {
max-height: 0;
width: inherit;
overflow: hidden;
-webkit-transition: max-height 0.85s ease-out;
transition: max-height 0.85s ease-out;
}
.flyout-dropdown-open {
max-height: 1000px;
-webkit-transition: max-height 0.85s ease-in;
transition: max-height 0.85s ease-in;
}
.flyout-dropdown-container .navlist-dropdown {
list-style-type: none;
padding: 0;
}
.flyout-dropdown-container .navlist-dropdown li:last-child {
border-bottom-width: 0;
}
/* Responsive Behaviour
-----------------------------------------------------*/
@media (min-width: 768px) {
/* keep negative margin */
.container-fluid > .navbar-header {
margin-right: -15px;
margin-left: -15px;
}
/* always show navbar-toggle */
.navbar-toggle {
display: block;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
</div>
</nav>
<!-- Flyout Navbar -->
<div class="navbar-flyout-container">
<div class="navbar-flyout">
<div class="navbar-flyout-header">
</div>
<ul class="navlist">
<li>item 1</li>
<li><a href="#">very loooooooooooooooooooooooooooooooooooooong item 2</a></li>
<li class="flyout-dropdown-item">Dropdown
<div class="flyout-dropdown-container">
<ul class="navlist-dropdown">
<li><a href="#">very looooooooooooooooooooooooooong dropdown item 1</a></li>
<li>dropdown item 2</li>
<li>dropdown item 3</li>
<li>dropdown item 4</li>
<li>dropdown item 5</li>
</ul>
</div>
</li>
<li>item 4</li>
<li>item 5</li>
<li>item 6</li>
</ul>
</div>
</div>
<!-- /Flyout Navbar -->
這是最期待的一致好評!謝謝 – Silvestre