响应式Bootstrap推送菜单

时间:2014-12-30 07:59:14

标签: javascript jquery html css twitter-bootstrap

我正在尝试创建响应式Bootstrap推送菜单,我已为计算机enter image description here

创建了此模板

对于移动设备,它看起来像enter image description here

因此,当我们点击下拉列表时,它应该向左侧显示并显示下拉菜单列表

这是我试过的代码

    <nav class="navbar navbar-inverse navbar-fixed-top">
            <div class="container
                <div class="navbar-header">
                 <div class="container-fluid">
                    <div class="row">
                        <div class="col-xs-2 col-md-2" style="height:30px;margin-top:5px;">
                            <button type="button" class="navbar-toggle toggle-menu menu-left push-body" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                            <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 class="col-xs-8 col-md-8" style="height:30px;margin-top:5px;">
                            <input type="text" placeholder="email" class="form-control">
                        </div>
                        <div class="col-xs-2 col-md-2" style="height:30px;margin-top:5px;">
                            <button type="submit" class="btn btn-success">submit</button>
                        </div>
                    </div>
                    <div class="collapse navbar-collapse cbp-spmenu cbp-spmenu-vertical cbp-spmenu-left" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                  <li class="active"><a href="#">Link</a></li>
                  <li><a href="#">Link</a></li>
                  <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">Dropdown <span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu">
                      <li><a href="#">Action</a></li>
                      <li><a href="#">Another action</a></li>
                      <li><a href="#">Something else here</a></li>
                      <li><a href="#">Another action</a></li>
                      <li><a href="#">Something else here</a></li>
                      <li><a href="#">Another action</a></li>
                      <li><a href="#">Something else here</a></li>
                      <li><a href="#">Another action</a></li>
                      <li><a href="#">Something else here</a></li>
                    </ul>
                  </li>
                </ul>
              </div>
                </div>
            </div>
            </div>
        </nav>
<script src="js/jPushMenu.js"></script>
    <script type="text/javascript">
      //<![CDATA[
      $(document).ready(function(){
        $('.toggle-menu').jPushMenu({closeOnClickLink: false});
        $('.dropdown-toggle').dropdown();
      });
      //]]>
    </script>

但是我无法向左侧推进。

2 个答案:

答案 0 :(得分:1)

这是你要找的东西吗

http://jsfiddle.net/w6qc954t/

您的模板http://jsfiddle.net/w6qc954t/2/

它的使用jPushMenu.js由takien在github而不是以下部分包括在那个js

$(window).resize(function() {
  $('.cbp-spmenu').v2p({
    height:'100vh'
  });
});

$(window).resize(); // trigger event so it shows on load
$(document).ready(function(){
        $('.toggle-menu').jPushMenu({closeOnClickLink: false});
        $('.dropdown-toggle').dropdown();
      });

答案 1 :(得分:0)

这已在这里得到解答,使用&#34; off canvas&#34; Bootstrap代码中提供的布局:Bootstrap 3 Slide in Menu / Navbar on Mobile