Bootstrap 3下拉菜单不适用于较小的屏幕尺寸(手机/平板电脑)

时间:2015-03-19 05:58:48

标签: jquery html5 twitter-bootstrap responsive-design

我被困了几天。基本上我有一些链接,点击时滚动到不同的部分。在桌面上正常工作,但当缩小到移动/平板电脑时,下拉链接只需在点击时关闭下拉菜单。这是我的代码:

 <!DOCTYPE html>
    <html lang="en">

    <head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Freelancer - Start Bootstrap Theme</title>

    <!-- Bootstrap Core CSS - Uses Bootswatch Flatly Theme:  http://bootswatch.com/flatly/ -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">

    <!-- Custom CSS -->
    <link href="css/freelancer.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="http://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
    <link href="http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic" rel="stylesheet" type="text/css">
    <link href="http://fonts.googleapis.com/css?family=Arvo" rel="stylesheet" type="text/css">
    <link href="http://fonts.googleapis.com/css?family=PT+Sans" rel="stylesheet" type="text/css">
    <link href='http://fonts.googleapis.com/css?family=Gentium+Basic:400,700|Open+Sans:400,600,300,800' rel='stylesheet' type='text/css'>

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>
<body id="page-top" class="index">
    <!-- Navigation -->
    <nav class="navbar navbar-default navbar-fixed-top">
        <div class="container">
          <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle collapsed" data- toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
              <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="#page-top"><img class="logoM" src="img/logosm.png" width="200" height="50"></a>
          </div>
          <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right">
              <li class="hidden">
                <a href="#page-top"></a>
              </li>
              <li class="page-scroll">
                <a href="#page-top">Home</a>
              </li>
              <li class="dropdown page-scroll">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Locations <span class="caret"></span></a>
                <ul class="dropdown-menu" role="menu">
                  <li><a href="#classes">Classes</a></li>
                  <li><a href="#locations">Locations</a></li>
                </ul>
              </li>
            <li class="page-scroll">
                        <a href="#about">Directors</a>
                    </li>
                    <li class="page-scroll">
                        <a href="#contact">Contact</a>
                    </li>
          </div><!--/.nav-collapse -->
      </nav>
    <!-- Header -->
    <header>
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <img class="img-responsive" src="img/profileSPC.png" alt="">
                    <div class="intro-text">
                        <span class="name">San Patricio Adult Literacy Council</span>
                        <hr class="star-light">
                        <span class="skills">Providing an opportunity to adults with their basic listening, speaking, reading, writing, and mathematical skills.</span>
                    </div>
                </div>
            </div>
        </div>
    </header>

    <!-- Portfolio Grid Section -->
    <section id="classes">
        <div class="container">
            <div class="row">
                <div class="col-lg-12 text-center">
                    <div class="classes-offered">
                        <h2 class="h2Class">Classes Offered</h2>
                        <hr class="star-primary">
                        <span class="classy">Literacy,ESL,GED &amp;Citizenship classes are offered throughout the year. Individual tutoring is available when volunteer tutors are available to meet with students on a one-to-one basis.</span>
                    </div>
                </div>
            </div>
            <div class="row equal">
                <div class="col-md-3">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                          <h3 class="panel-title text-center">Basic Literacy</h3>
                        </div>

                        <div class="panel-body">Individual or Group Tutoring Instruction is available for students who wish to improve on their skills:<br>
                            <ul class="list-group">
                                <li class="list-group-item">Basic Listening</li>
                                <li class="list-group-item">Speaking</li>
                                <li class="list-group-item">Reading/Mathematical</li>
                                <li class="list-group-item">Writing/Computer Skills</li>
                            </ul>
                        </div>

                        <div class="panel-footer clearfix"><p><a class="btn btn-primary btn-sm btn-bottom" href="#" role="button">Learn more</a></p>
                         </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                          <h3 class="panel-title text-center">ESL Literacy</h3>
                        </div>
                        <div class="panel-body">Individual tutoring or group instruction is available for non-native speakers of English wishing to improve their skills.<br>
                            <ul class="list-group">
                                <li class="list-group-item">Basic Listening</li>
                                <li class="list-group-item">Speaking</li>
                                <li class="list-group-item">Reading</li>
                                <li class="list-group-item">Writing skills</li>
                            </ul>
                        </div>

                        <div class="panel-footer clearfix"><p><a class="btn btn-primary btn-sm btn-bottom" href="#" role="button">Learn more</a></p></div>
                         </div>
                </div>
                <div class="col-md-3">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                          <h3 class="panel-title text-center">GED</h3>
                        </div>
                        <div class="panel-body">GED Testing preparation is offered in cooperation with Coastal Bend Community College Adult Education Department.<br>
                            <ul class="list-group">
                                <li class="list-group-item">GED Prep</li>
                                <li class="list-group-item">One-to-One tutoring</li>
                                <li class="list-group-item">6 hrs./week - Online GED assignments</li>
                            </ul>
                        </div>

                        <div class="panel-footer clearfix"><p><a class="btn btn-primary btn-sm btn-bottom" href="#" role="button">Learn more</a></p></div>
                         </div>
                </div>
                <div class="col-md-3">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                          <h3 class="panel-title text-center">Citizenship</h3>
                        </div>
                        <div class="panel-body">Instruction and review is available for students wishing to prepare for United States citizenship processing. For more information please call the SPCALC office or your community library.<br>

                            <ul class="list-group">
                                <li class="list-group-item">U.S. Citizenship Prep</li>
                                <li class="list-group-item">Instruction and Review of forms</li>
                                <li class="list-group-item">The Naturalization Process</li>
                            </ul>
                        </div>

                        <div class="panel-footer clearfix"><p><a class="btn btn-primary btn-sm btn-bottom" href="#" role="button">Learn more</a></p></div>
                         </div>
                </div>
        </div>
    </section>

<!-- Scroll to Top Button (Only visible on small and extra-small screen sizes) -->
    <div class="scroll-top page-scroll visible-xs visble-sm">
        <a class="btn btn-primary" href="#page-top">
            <i class="fa fa-chevron-up"></i>
        </a>
    </div>


    <!-- jQuery -->
    <script src="js/jquery.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <!-- Bootstrap Core JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

    <!-- Plugin JavaScript -->
    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>

    <script src="js/classie.js"></script>
    <script src="js/cbpAnimatedHeader.js"></script>


    <!-- Contact Form JavaScript -->
    <script src="js/jqBootstrapValidation.js"></script>
    <script src="js/contact_me.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="js/freelancer.js"></script>

</body>


</html>

freelancer.js代码

// jQuery for page scrolling feature - requires jQuery Easing plugin
    $(function() {
    $('body').on('click', '.page-scroll a', function(event) {
        var $anchor = $(this);
        $('html, body').stop().animate({
            scrollTop: $($anchor.attr('href')).offset().top
        }, 1500, 'easeInOutExpo');
        event.preventDefault();
    });
});

     // Floating label headings for the contact form
    $(function() {
    $("body").on("input propertychange", ".floating-label-form-group",  function(e) {
        $(this).toggleClass("floating-label-form-group-with-value", !!  $(e.target).val());
    }).on("focus", ".floating-label-form-group", function() {
        $(this).addClass("floating-label-form-group-with-focus");
    }).on("blur", ".floating-label-form-group", function() {
        $(this).removeClass("floating-label-form-group-with-focus");
    });
});

     // Highlight the top nav as scrolling occurs
    $('body').scrollspy({
    target: '.navbar-fixed-top'
})

    // Closes the Responsive Menu on Menu Item Click
    $('.navbar-collapse ul li a').click(function() {
    $('.navbar-toggle:visible').click();
});

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题并通过将类名'page-scroll'添加到freelancer.js来解决它,以便只触发此值属性。 在freelancer.js中,这将是:     $('。navbar-collapse ul li.page-scroll a')。cl [...]。
我希望这对你有任何帮助,因为这是我的第一个贡献,你们很多人帮助了我。