相对于切换导航菜单移动fa-bars

时间:2015-02-18 17:38:56

标签: javascript css html5 twitter-bootstrap-3 font-awesome

我正在设计一个网页,其中有一个切换的导航菜单,该菜单会在点击fa-bars按钮时展开,并在再次单击同一按钮时折叠。我能够成功地做到这一点,如下面的html和css

HTML

<div id="wrapper">
        <div id="sidebar-wrapper">
        <a id="menu-toggle" href="#menu-toggle" class="btn btn-dark btn-lg"><i class="fa fa-bars"></i></a> 
            <ul class="sidebar-nav">
                <li class="sidebar-brand">
                    <a href="#">
                        Brand
                    </a>
                </li>
                <li>
                    <a href="#">Dashboard</a>
                </li>
                <li>
                    <a href="#">Shortcuts</a>
                </li>
                <li>
                    <a href="#">Overview</a>
                </li>
                <li>
                    <a href="#">Events</a>
                </li>
                <li>
                    <a href="#">About</a>
                </li>
                <li>
                    <a href="#">Services</a>
                </li>
                <li>
                    <a href="#">Contact</a>
                </li>
            </ul>
        </div>


        <a id="menu-toggle" href="#menu-toggle" class="btn btn-dark btn-lg"><i class="fa fa-bars"></i></a> 

侧栏的CSS

#wrapper {
    padding-left: 0;
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;
}

#wrapper.toggled {
    padding-right: 250px;
}

#sidebar-wrapper {
    z-index: 1000;
    position: fixed;
    right: 250px;
    width: 0;
    height: 100%;
    margin-left: -250px;
    overflow-y: auto;
    background: #000;
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;
}

#wrapper.toggled #sidebar-wrapper {
    width: 250px;
}

#page-content-wrapper {
    width: 100%;
    position: absolute;
    padding: 105px;
}

#wrapper.toggled #page-content-wrapper {
    position: absolute;
    margin-right: -250px;
}

/* Sidebar Styles */

.sidebar-nav {
    position: absolute;
    top: 0;
    width: 250px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.sidebar-nav li {
    text-indent: 20px;
    line-height: 40px;
}

.sidebar-nav li a {
    display: block;
    text-decoration: none;
    color: #999999;
}

.sidebar-nav li a:hover {
    text-decoration: none;
    color: #fff;
    background: rgba(255,255,255,0.2);
}

.sidebar-nav li a:active,
.sidebar-nav li a:focus {
    text-decoration: none;
}

.sidebar-nav > .sidebar-brand {
    height: 65px;
    font-size: 18px;
    line-height: 60px;
}

.sidebar-nav > .sidebar-brand a {
    color: #999999;
}

.sidebar-nav > .sidebar-brand a:hover {
    color: #fff;
    background: none;
}

Javascript to toggle

 $("#menu-toggle").click(function(e) {
        e.preventDefault();
        $("#wrapper").toggleClass("toggled");
    });

上面的代码似乎运行正常,但我试图相对于切换导航移动fa-bars而不是将它保持在同一位置

现在我有以下页面截图

enter image description here

在上面的图片中,我在固定位置有3条按钮,但是当导航栏被展开时我希望它在包装器之外,并且想要它在右上角,因为它在导航折叠时在上面的图像中< / p>

0 个答案:

没有答案