菜单切换时更改符号或图标

时间:2014-08-05 14:58:00

标签: menu twitter-bootstrap-3 toggle

我试图找出如何在切换发生时更改菜单图标按钮...与菜单图标从汉堡包图标变为切换之间的X时的概念相同。我正在使用bootstrap 3框架,由于某些原因我无法在打开和关闭侧栏菜单之间交替显示图标(切换工作正常无法在切换发生时无法更改图标)。我假设这是一个普遍实现的bootstraps CSS和JS框架......非常感谢任何和所有的帮助!

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

    <!-- Custom CSS -->
    <link href="css/simple-sidebar.css" rel="stylesheet">
    <link href="css/jquery-mobile.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="css/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">

    <!-- Timeline CSS -->
    <link href="css/plugins/timeline.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/sb-admin-2.css" rel="stylesheet">

    <!-- Morris Charts CSS -->
    <link href="css/plugins/morris.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="font-awesome-4.1.0/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">

    <!-- 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">
 <div id="wrapper">

        <!-- Sidebar -->
        <div id="sidebar-wrapper">
            <ul class="sidebar-nav"><br><br><br><br><br><br>
                <li class="sidebar-brand">
                    <h3>
                       DDI Work
                    </h3>
                </li>
                <li>
                    <a href="#">Landscapes</a>
                </li>
                <li>
                    <a href="#">Pavements</a>
                </li>
                <li>
                    <a href="#">Pools & Spas</a>
                </li>
                <li>
                    <a href="#">Walls</a>
                </li>
                <li>
                    <a href="#">Outdor Features</a>
                </li>
                <li>
                    <a href="#">Gardens</a>
                </li>
            </ul>
        </div>
 <!-- /#sidebar-wrapper -->

    <!-- Page Content -->
        <div id="page-content-wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <br><br><br><a href="#menu-toggle" class="btn btn-default"  id="menu-toggle"><span class="fa arrow"></span></a>         
            <span class="fa arrow">::before</span>          
                    </div>
                </div>
            </div>

JS:          

<!-- Bootstrap Core JavaScript -->
<script src="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>

<!-- Menu Toggle Script -->
<script>
$("#menu-toggle").click(function(e) {
    e.preventDefault();
    $("#wrapper").toggleClass("toggled");
});
</script>

1 个答案:

答案 0 :(得分:0)

这是Glyphicon的一个示例,但您可以使用任何字体。而不是跨度:在使用fa之前:之前你使用的字体很棒。

http://jsbin.com/betibo/1/edit

CSS:

#wrapper.toggled #menu-toggle span:before {content:'\2212'}

将此处的内容更改为切换类的unicode

<div id="wrapper">
  <a href="#menu-toggle" class="btn btn-primary"  id="menu-toggle"><span class="glyphicon glyphicon-plus"></span></a> 
  </div>

jQuery - 和你一样