Bootstrap 3 :(移动)导航栏在您单击下拉菜单后自动关闭

时间:2019-05-29 10:43:19

标签: html twitter-bootstrap twitter-bootstrap-3 drop-down-menu

您好,我需要您的专业知识,因为它在桌面模式下可以完美运行,但是如果它的移动模式在单击下拉菜单后无法正常运行,则会自动关闭整个导航栏,

<li class="dropdown">
                            <a data-toggle="dropdown" > Shop </a>
                            <ul class="dropdown-menu">
                                <li><a href="<?php echo home_url(); ?>/shop">All Inventory</a></li>
                                <li><a href="<?php echo home_url(); ?>/product-category/designer-bags">Designer Bags</a></li>
                                <li><a href="<?php echo home_url(); ?>/product-category/designer-accessories">Designer Accessories</a></li>
                                <li><a href="<?php echo home_url(); ?>/outright-buying/">Outright Buying</a></li>
                                <li><a href="<?php echo home_url(); ?>/Consignment">Consignment</a></li>
                            </ul>
                    </li>

1 个答案:

答案 0 :(得分:0)

navbar-toggle上单击时,以下代码展开子菜单 然后根据子菜单的打开/关闭状态将aria-expanded更改为正确的值

function opensubmenus() {
    if ($(window).width() < 768) {
        $("#top-navbar-collapse li").addClass('open');
        $("#top-navbar-collapse li a").attr('aria-expanded','true');
    }else{
        $("#top-navbar-collapse li").removeClass('open');
        $("#top-navbar-collapse li a").attr('aria-expanded','false');
    }
}

$('#top-menu .navbar-toggle').click(function(){
    setTimeout(opensubmenus, 100);
});

$(window).resize(opensubmenus);
opensubmenus();