如何在bootstrap中从左到右进行滑动切换?

时间:2015-06-28 10:48:02

标签: javascript jquery twitter-bootstrap twitter-bootstrap-3



<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/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"/>


<nav class="navbar navbar-default">
 <div class="container">
  <div class="row">
      <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
        </div>
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <!-- Search Box -->
          <form class="navbar-form navbar-left" role="search" id="search_mobile">
            <div class="form-group">
              <input type="text" class="form-control" placeholder="Enter your manual keyword">
            </div>
            <button type="submit" class="btn btn-default">Search</button>
          </form>
          <ul class="nav navbar-nav"> 
            <li><a href="#">MANUALS</a></li>
            <li><a href="#">NEWS</a></li>
            <li><a href="#">SPARE PART</a></li>
            <li><a href="#">WHERE TO BUY</a></li>
            <li><a href="#">SUPPORT</a></li>
            <li><a href="#">EDIT BOOK</a></li>
            <li><a href="#">ADMIN</a></li>
            <!-- <li><a href="#" id="logout">LOG OUT</a></li> -->
          </ul>
        </div><!-- /.navbar-collapse -->
      </div><!-- /.container-fluid -->
    </div>
  </div>
</nav>
&#13;
&#13;
&#13;

我在移动视图上使用自举式响应式导航栏。 当我单击按钮时,导航栏菜单从上到下显示。

我该怎样做才能从左到右制作?(请记住将窗口调整为移动尺寸)。

3 个答案:

答案 0 :(得分:1)

你可以查看这个流行的Bootstrap前叉: Jasny Bootstrap

左下角有相同的幻灯片。

<link href="http://www.jasny.net/bootstrap/dist/css/jasny-bootstrap.min.css" rel="stylesheet"/>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="http://www.jasny.net/bootstrap/dist/js/jasny-bootstrap.min.js"></script>

<nav id="myNavmenu" class="navmenu navmenu-default navmenu-fixed-left offcanvas" role="navigation">
  <a class="navmenu-brand" href="#">Brand</a>
  <ul class="nav navmenu-nav">
    <li class="active"><a href="#">Home</a></li>
    <li><a href="#">Link</a></li>
    <li><a href="#">Link</a></li>
  </ul>
</nav>
<div class="navbar navbar-default navbar-fixed-top">
  <button type="button" class="navbar-toggle" data-toggle="offcanvas" data-target="#myNavmenu" data-canvas="body">
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>
</div>

答案 1 :(得分:0)

您需要覆盖以下两个属性才能将其归档。在这里你也应该使用 pull-left bootstrap类,这个类元素只移动到左侧但不设置边距。我认为你应该根据要求重写。

.nav-left{
  float: left !important;
  margin: 8px 15px !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/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"/>


<nav class="navbar navbar-default">
 <div class="container">
  <div class="row">
      <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed nav-left" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
        </div>
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <!-- Search Box -->
          <form class="navbar-form navbar-left" role="search" id="search_mobile">
            <div class="form-group">
              <input type="text" class="form-control" placeholder="Enter your manual keyword">
            </div>
            <button type="submit" class="btn btn-default">Search</button>
          </form>
          <ul class="nav navbar-nav"> 
            <li><a href="#">MANUALS</a></li>
            <li><a href="#">NEWS</a></li>
            <li><a href="#">SPARE PART</a></li>
            <li><a href="#">WHERE TO BUY</a></li>
            <li><a href="#">SUPPORT</a></li>
            <li><a href="#">EDIT BOOK</a></li>
            <li><a href="#">ADMIN</a></li>
            <!-- <li><a href="#" id="logout">LOG OUT</a></li> -->
          </ul>
        </div><!-- /.navbar-collapse -->
      </div><!-- /.container-fluid -->
    </div>
  </div>
</nav>

答案 2 :(得分:0)

使用Jasny Bootstrap插入式插件,默认类为“navmenu-fixed-left”。您可以将班级更改为“navmenu-fixed-right”以使菜单从右侧滑入:

<div class="navmenu navmenu-default navmenu-fixed-right offcanvas" role="navigation">
<ul class="nav navmenu-nav">
<li><a href="about.php">About</a></li>
<li><a href="capabilities.php">Capabilities</a></li>
</ul>
</div>

如果您还希望切换按钮显示在右侧,则需要调整一些CSS:

.navbar-default .navbar-toggle-box {
float: right;
margin-left: 15px;
margin-right: 0;
margin-top: 0;
position: absolute;
right: 0;
}