首页 > 其他 > 详细

Bootstrap 手风琴搭配导航条实现常用菜单栏

时间:2016-01-15 12:43:35      阅读:253      评论:0      收藏:0      [点我收藏+]

效果

技术分享

HTML代码

    <div class="sidebar">
        <div class="mc-search">
            <div class="input-group">
                <input type="text" class="form-control" placeholder="Search...">
            <span class="input-group-btn">
                <button type="button" class="btn btn-default"><i class="fa fa-search"></i></button>
            </span>
            </div>
        </div>
        <div class="navbar navbar-default" id="mycollapse">
            <!-- <ul class="nav navbar-nav nav-pills nav-stacked"> -->
            <ul class="nav nav-pills nav-stacked">
                <li><a href="#"><i class="fa fa-dashboard fa-fw"></i> DashBord</a></li>

                <li>
                    <a href="#second-level-1" class="second-level accordion-toggle"
                       data-toggle="collapse"
                       data-parent="#mycollapse">
                        <i class="fa fa-table fa-fw"></i> Table<i
                            class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul class="nav collapse" id="second-level-1">
                        <li><a href="#">数据库测试</a></li>
                        <li><a href="#">数据库测试</a></li>
                        <li><a href="#">数据库测试</a></li>
                    </ul>
                </li>

                <li><a href="#"><i class="fa fa-bar-chart fa-fw"></i> Chart</a></li>
                <li><a href="#"><i class="fa fa-edit fa-fw"></i> Form</a></li>
                <li>
                    <a href="#second-level-2" class="second-level accordion-toggle"
                       data-toggle="collapse"
                       data-parent="#mycollapse">
                        <i class="fa fa-table fa-fw"></i> Table<i
                            class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul class="nav collapse" id="second-level-2">
                        <li><a href="#">数据库测试</a></li>
                        <li><a href="#">数据库测试</a></li>
                        <li><a href="#">数据库测试</a></li>
                    </ul>
                </li>
                <li><a href="#"><i class="fa fa-wrench fa-fw"></i> UI Element</a></li>
                <li>
                    <a href="#second-level-3" class="second-level accordion-toggle"
                       data-toggle="collapse" data-parent="#mycollapse">
                        <i class="fa fa-table fa-fw"></i> Table<i
                            class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul class="nav collapse" id="second-level-3">
                        <li><a href="#">数据库测试</a></li>
                        <li><a href="#">数据库测试</a></li>
                        <li><a href="#">数据库测试</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>

JS代码

$(function () {
    $(document).on(‘click‘, ‘.accordion-toggle‘, function(event) {
        event.stopPropagation();
        var $this = $(this);
        var parent = $this.data(‘parent‘);
        var actives = parent && $(parent).find(‘.collapse.in‘);

        // From bootstrap itself
        if (actives && actives.length) {
            actives.data(‘collapse‘);
            actives.collapse(‘hide‘);
        }

        var target = $this.attr(‘data-target‘) || (href = $this.attr(‘href‘)) && href.replace(/.*(?=#[^\s]+$)/, ‘‘); //strip for ie7
        $(target).collapse(‘toggle‘);
    });
})

效果

  1. 点击一个可以展开下拉菜单。
  2. 点击另外一个如果有下拉菜单则自动关闭上一个展开

 

Bootstrap 手风琴搭配导航条实现常用菜单栏

原文:http://www.cnblogs.com/LiuChunfu/p/5132702.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!