单击链接后滑回画布菜单

时间:2014-09-30 02:16:34

标签: javascript html css twitter-bootstrap

我正在使用Jansy Off Canvas菜单(found here)作为我正在处理的网站。我将菜单滑出,如果再次单击汉堡菜单,它会向后滑动。但是,如果用户也点击其中一个链接,我希望它可以退回。现在它还没有出来。

我尝试使用此代码:

$(".navbar-toggle").unbind().on("click", function () {
        console.log("toggle");
        $("#myNavmenu a").offcanvas("hide")
    });

但只有点击汉堡菜单才会被解雇。

这就是我的HTML中汉堡菜单的样子:

    <!-- burger menu -->
<div class="container">
    <div class="row">
        <div id="burgerWrapper">
             <nav id="myNavmenu" class="navmenu navmenu-default navmenu-fixed-left offcanvas" role="navigation">
                <ul class="nav navmenu-nav">
                    <!-- Hidden li included to remove active class from about link when scrolled up past about section -->
                    <li class="hidden"><a class="page-scroll" href="#page-top"></a></li>
                    <li><a href="#criminalLaw" class="page-scroll">CRIMINAL LAW</a></li>
                    <li><a href="#criminalLocalCourt" class="page-scroll">LOCAL COURT MATTERS</a></li>
                    <li><a href="#criminalMentalHealth" class="page-scroll">SECTION 32 APPLICATIONS</a></li>
                    <li><a href="#criminalConviction" class="page-scroll">CONVICTION AND SEVERITY APPEALS</a></li>
                    <li><a href="#criminalPenalties" class="page-scroll">INDICTABLE MATTERS</a></li>
                    <li><a href="#criminalFee" class="page-scroll">FEE ARRANGEMENTS</a></li>
                 </ul>
            </nav>
            <div class="navbar navbar-default navbar-fixed-top" data-spy="affix" data-offset-top="200">
                <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>
        </div>
    </div>
</div>
<!-- end burger menu -->

1 个答案:

答案 0 :(得分:0)

我相信以下代码可以解决您的问题。

&#13;
&#13;
$(".nav li a").click(function (){
    
  $('#myNavmenu').offcanvas("hide");

});    
&#13;
&#13;
&#13;