Javascript 使用引导的响应菜单

Javascript 使用引导的响应菜单,javascript,jquery,html,twitter-bootstrap,responsive-design,Javascript,Jquery,Html,Twitter Bootstrap,Responsive Design,有人能帮我使用引导CSS创建菜单吗 引导菜单的每个教程都不能完全满足我的要求 那么,有谁能告诉我如何创建响应菜单 图像包含两个图像:一个用于普通浏览器,另一个用于移动设备 我尝试了以下代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Example of Twitter Bootstrap 3 Static Navbar Extended&

有人能帮我使用引导CSS创建菜单吗 引导菜单的每个教程都不能完全满足我的要求 那么,有谁能告诉我如何创建响应菜单

图像包含两个图像:一个用于普通浏览器,另一个用于移动设备

我尝试了以下代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example of Twitter Bootstrap 3 Static Navbar Extended</title>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
     <style type="text/css">
         .bs-example{
        margin: 20px;
            }
     </style>
<script>

</script>
</head> 
<body>
<div class="bs-example">
    <nav role="navigation" class="navbar navbar-default">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
           <!--  <a href="#" class="navbar-brand">Brand</a> -->
        </div>
        <!-- Collection of nav links, forms, and other content for toggling -->
        <div id="navbarCollapse" class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="#">Home</a>                </li>
                <li><a href="#">Profile</a></li>
                <li><a href="#">Login</a></li>
              </ul>
            <!-- <ul class="nav navbar-nav">
                <li><a href="#">Login</a></li>
            </ul> -->
        </div>
    </nav>
</div>
</body>
</html>

TwitterBootstrap3静态导航栏扩展示例
.bs示例{
利润率:20px;
}
切换导航

您检查过这些示例了吗

你需要什么就做什么

此外,该实用程序允许您创建引导导航栏

更新


切换导航
$(文档).ready(函数(){ //用于创建的控件 如果($(窗口).width()<767){ $(“#链接”).show(); } }); $(文档).load($(窗口).bind(“调整大小”,do_菜单)); 函数do_菜单(){ 如果($(窗口).width()<767){ $(“#链接”).show(); }否则{ $(“#链接”).hide(); } }
我已经修改了twitter引导HTML代码,我相信下面的解决方案与您的期望非常接近

<!-- Static navbar -->
      <div class="navbar navbar-default" role="navigation">
        <div class="container-fluid">
          <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
              <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 hidden-lg" href="#" data-toggle="dropdown">Project name</a>
          </div>
          <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
              <li class="active"><a href="#">1 First Topic</a></li>
              <li><a href="#">1 First Topic</a></li>
              <li><a href="#">1 First Topic</a></li>

            </ul>

          </div><!--/.nav-collapse -->
        </div><!--/.container-fluid -->
      </div>

切换导航
我得到了我的解决方案: 以下是我需要的代码:

                    <!DOCTYPE html>
                    <html lang="en">
                    <head>
                    <meta charset="UTF-8">
                    <title>Example of Twitter Bootstrap 3 Static Navbar Extended</title>
                    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
                    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
                    <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
                    <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
                    <style type="text/css">
                        .bs-example{
                            margin: 20px;
                        }
                    </style>
                    <script>
                      $(document).ready(function(){

                                $(window).resize(function(){

                                    console.log($(window).width());
                                    if($(window).width()<767)
                                    {
                                        $(".navbar-brand").html($(".active>a").text());
                                    }
                                    else
                                    {
                                        $(".navbar-brand").html("");
                                    }

                                });

                                $("ul>li").click(function(){

                                        //alert($(this).find("a").text());
                                        $(".active").removeClass("active");
                                        $(this).addClass("active");
                                        if($("#navbarCollapse").hasClass("in"))
                                        {
                                            $("#navbarCollapse").removeClass("in")
                                            $("#navbarCollapse").addClass("collapse")
                                        }

                                        if($(window).width()<767)
                                        {
                                            $(".navbar-brand").html($(".active>a").text());
                                        }
                                        else
                                        {
                                            $(".navbar-brand").html("");
                                        }


                                });
                      });
                    </script>
                    </head> 
                    <body>
                    <div class="bs-example">
                        <nav role="navigation" class="navbar navbar-default">
                            <!-- Brand and toggle get grouped for better mobile display -->
                            <div class="navbar-header">
                                <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
                                    <span class="sr-only">Toggle navigation</span>
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                </button>
                                <a href="#" class="navbar-brand"></a>  
                            </div>
                            <!-- Collection of nav links, forms, and other content for toggling -->
                            <div id="navbarCollapse" class="collapse navbar-collapse">
                                <ul class="nav navbar-nav">
                                    <li class="active"><a href="#">Home</a></li>
                                    <li><a href="#">Profile</a></li>
                                    <li><a href="#">Login</a></li>
                                  </ul>
                            </div>
                        </nav>
                    </div>
                    </body>
                    </html>                                     

TwitterBootstrap3静态导航栏扩展示例
.bs示例{
利润率:20px;
}
$(文档).ready(函数(){
$(窗口)。调整大小(函数(){
log($(window.width());
if($(窗口).width()

是的,在所有这些示例中,当我使用移动设备时,它在顶部显示品牌名称。我想要活动链接,而不是项目名称。这意味着链接已被单击。感谢链接,但在该链接中,我无法更改功能,而不是菜单的名称。您希望看到菜单中的第一个项目吗?是的,我将单击现在创建的项目然后更新答案:)不,尼科洛,情况并非如此,你只是改变了navbar的品牌,但我想当我点击菜单名称和菜单应该关闭的特定项目时,总是一个好主意,发布一些你迄今为止尝试过的代码,向人们展示你自己确实努力解决了这个问题。
                    <!DOCTYPE html>
                    <html lang="en">
                    <head>
                    <meta charset="UTF-8">
                    <title>Example of Twitter Bootstrap 3 Static Navbar Extended</title>
                    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
                    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
                    <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
                    <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
                    <style type="text/css">
                        .bs-example{
                            margin: 20px;
                        }
                    </style>
                    <script>
                      $(document).ready(function(){

                                $(window).resize(function(){

                                    console.log($(window).width());
                                    if($(window).width()<767)
                                    {
                                        $(".navbar-brand").html($(".active>a").text());
                                    }
                                    else
                                    {
                                        $(".navbar-brand").html("");
                                    }

                                });

                                $("ul>li").click(function(){

                                        //alert($(this).find("a").text());
                                        $(".active").removeClass("active");
                                        $(this).addClass("active");
                                        if($("#navbarCollapse").hasClass("in"))
                                        {
                                            $("#navbarCollapse").removeClass("in")
                                            $("#navbarCollapse").addClass("collapse")
                                        }

                                        if($(window).width()<767)
                                        {
                                            $(".navbar-brand").html($(".active>a").text());
                                        }
                                        else
                                        {
                                            $(".navbar-brand").html("");
                                        }


                                });
                      });
                    </script>
                    </head> 
                    <body>
                    <div class="bs-example">
                        <nav role="navigation" class="navbar navbar-default">
                            <!-- Brand and toggle get grouped for better mobile display -->
                            <div class="navbar-header">
                                <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
                                    <span class="sr-only">Toggle navigation</span>
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                </button>
                                <a href="#" class="navbar-brand"></a>  
                            </div>
                            <!-- Collection of nav links, forms, and other content for toggling -->
                            <div id="navbarCollapse" class="collapse navbar-collapse">
                                <ul class="nav navbar-nav">
                                    <li class="active"><a href="#">Home</a></li>
                                    <li><a href="#">Profile</a></li>
                                    <li><a href="#">Login</a></li>
                                  </ul>
                            </div>
                        </nav>
                    </div>
                    </body>
                    </html>