我想在Bootstrap 3中实现mmenu,但我被卡住了。我想要顶部导航,当折叠时,我希望它变为左滑动菜单。提前感谢您的帮助。
编辑:我做了这个:https://github.com/purgeru/mmenu-Bootstrap-3.如果有人想做出贡献。
这可以在没有mmenu
的情况下完成,添加一些CSS。
我建议你创建2个不同的导航:
- 用于
-sm
、-md
和-lg
设备的.navbar.navbar-fixed-top
- 用于
-xs
设备的.sidebar-offcanvas
有关基于Offcanvas模板的工作示例,请参阅此Bootply。
注释示例:
<!-- Classic nav -->
<div class="navbar navbar-fixed-top navbar-inverse" role="navigation">
<div class="container">
<div class="navbar-header">
<!-- We change data-toggle to "offcanvas" -->
<button type="button" class="navbar-toggle" data-toggle="offcanvas">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
</div>
</div>
<div class="container">
<!-- You can use .row-offcanvas-left or .row-offcanvas-right -->
<div class="row row-offcanvas row-offcanvas-left">
<!-- Here is the offcanvas nav, with .visible-xs class -->
<div class="col-xs-6 visible-xs sidebar-offcanvas" id="sidebar" role="navigation">
<div class="list-group">
<a href="#" class="list-group-item active">Home</a>
<a href="#" class="list-group-item">About</a>
<a href="#" class="list-group-item">Contact</a>
</div>
</div>
<div class="col-12">
Content
</div>
</div>
</div>
你需要一些CSS:
/*
* Off Canvas
* --------------------------------------------------
*/
@media screen and (max-width: 767px) {
.row-offcanvas {
position: relative;
-webkit-transition: all 0.25s ease-out;
-moz-transition: all 0.25s ease-out;
transition: all 0.25s ease-out;
}
.row-offcanvas-right .sidebar-offcanvas { right: -50%; }
.row-offcanvas-right .sidebar-offcanvas .list-group { padding-right: 10px; }
.row-offcanvas-right.active { right: 50%; }
.row-offcanvas-left .sidebar-offcanvas { left: -50%; }
.row-offcanvas-left .sidebar-offcanvas .list-group { padding-left: 10px; }
.row-offcanvas-left.active { left: 50%; }
.sidebar-offcanvas {
position: absolute;
top: 0;
width: 50%; /* 6 columns */
}
}
还有几行JS:
$(document).ready(function() {
$('[data-toggle=offcanvas]').click(function() {
$('.row-offcanvas').toggleClass('active');
});
});