我想在移动屏幕上创建带有新按钮视图的新菜单
像这样
http://i.stack.imgur.com/zMQjQ.png
如果屏幕不是手机,则此菜单隐藏

        <nav class="navbar navbar-default" role="navigation">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-menubuilder">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <button type="button" class="navbar-toggle btn-sociall pull-left" data-toggle="collapse" data-target=".navbar-social">
                <span class="icon-bar"></span>
            </button>
        </div>
        <div class="collapse navbar-collapse navbar-menubuilder">
            <ul class="nav navbar-nav">
                <li><a href="#">Link</a></li>
                <li><a href="#">Link</a></li>
                <li><a href="#">Link</a></li>
                <li><a href="#">Link</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
                    <ul class="dropdown-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="#">Separated link</a></li>
                        <li><a href="#">One more separated link</a></li>
                    </ul>
                </li>
            </ul>
        </div><!-- /.navbar-collapse -->
        <div class="collapse  navbar-collapse navbar-social">
            <ul class="nav  navbar-nav navbar-social">
                <li><a href="#">Link</a></li>
                <li><a href="#">Link</a></li>
                <li><a href="#">Link</a></li>
                <li><a href="#">Link</a></li>
            </ul>
        </div><!-- /.navbar-collapse -->

    </nav>


此代码重新运行
http://i.stack.imgur.com/F0Eje.png

我的答案是有更好的方法。我用隐藏的类。

<nav class="navbar navbar-default" role="navigation">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle " data-toggle="collapse" data-target=".navbar-menubuilder">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <button type="button" class="navbar-toggle btn-social pull-left" data-toggle="collapse" data-target=".navbar-social">
            <span class="icon-social"></span>
        </button>
    </div>
    <div class="collapse navbar-collapse navbar-menubuilder">
        <ul class="nav navbar-nav">
            <li><a href="#">Link</a></li>
            <li><a href="#">Link</a></li>
            <li><a href="#">Link</a></li>
            <li><a href="#">Link</a></li>
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
                <ul class="dropdown-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="#">Separated link</a></li>
                    <li><a href="#">One more separated link</a></li>
                </ul>
            </li>
        </ul>
    </div><!-- /.navbar-collapse -->
    <div class="collapse hidden navbar-collapse navbar-social ">
        <ul class="nav hidden navbar-nav navbar-social ">
            <li><a href="#"><span class="menu-social menu-facebook"></span>Facebook</a></li>
            <li><a href="#"><span class="menu-social menu-twitter"></span>twitter</a></li>
            <li><a href="#"><span class="menu-social menu-linkedin"></span>Linkedin</a></li>
            <li><a href="#"><span class="menu-social menu-skype"></span>Skype</a></li>
            <li><a href="#"><span class="menu-social menu-googleplus"></span>GooglePlus</a></li>
            <li><a href="#"><span class="menu-social menu-youtube"></span>Youtube</a></li>
            <li><a href="#"><span class="menu-social menu-share"></span>Share</a></li>
            <li><a href="#"><span class="menu-social menu-rss"></span>Rss</a></li>
        </ul>
    </div><!-- /.navbar-collapse -->
</nav>


并添加代码javascript

$(function() {
  if(($(window).width() <= 767)) {
    $(".navbar-social").removeClass('hidden');
  }
});

最佳答案

尝试添加类visible-xs

那是visible/hidden-(screensize),是的,您可以将它们组合在一起:hidden-sm hidden-md hidden-lg也可以。

因此,更改此设置(从第二行开始):

<div class="navbar-header">
   ...
</div>




<div class="navbar-header visible-xs">
    ...
</div>

关于javascript - 如何仅在移动设备上添加新按钮导航栏 View (使用 bootstrap ),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29378497/

10-13 08:59