0

我有一个我创建的 HTML Jquery 菜单栏,我需要创建一个按钮来显示和隐藏菜单。

我认为我也可以在其中使用 JQUERY 通过单击菜单按钮来显示/隐藏菜单栏。

菜单栏就像这样 http://codecanyon.net/theme_previews/2867525-jquery-dashboard-vertical-navigation?index=1

我在想我可以以某种方式将所有按钮折叠到顶部图标中?这可能吗?

HTML

<div class="sidebar">
    <div class="logo">
    </div>
    <ul>
        <li>
            <a href="#">Campaigns </a>
            <ul class="submenu">
                <li><a href="#">Sub Menu1</a></li>
                <li><a href="#">Sub Menu2</a></li>
            </ul>
        </li>
        <li>
            <a href="#">Links </a>
            <ul class="submenu">
                <li><a href="#">Sub Menu1</a></li>
                <li><a href="#">Sub Menu2</a></li>
            </ul>
        </li>
        <li>
            <a href="#">Media </a>
            <ul class="submenu">
                <li><a href="#">Sub Menu1</a></li>
                <li><a href="#">Sub Menu2</a></li>
            </ul>
        </li>
        <li><a href="#">History</a></li>
        <li>
            <a href="#">Messages </a>           
            <ul class="submenu">
                <li><a href="#">Sub Menu1</a></li>
                <li><a href="#">Sub Menu2</a></li>
            </ul>
        </li>
        <li>
            <a href="#">Maintenance </a>            
            <ul class="submenu">
                <li><a href="#">Sub Menu1</a></li>
                <li><a href="#">Sub Menu2</a></li>
            </ul>
        </li>
    </ul>
</div>

<div class="content">
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh     euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim     veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea     commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse     molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et     iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te     feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil     imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem     insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes     demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam     processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam     littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis     per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum     clari, fiant sollemnes in futurum.</p>
</div>

<script type="text/javascript"         src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="js/custom.js"></script>
</body>
</html>

CSS html { 高度:100%; }

body {
margin:0;
padding: 0;
height: 100%;
font-family: Arial;
font-size: 12px;
background: #f3f3f3;
}

*:focus {
border: none;
outline: none;
}

.content {
padding: 25px 25px 25px 250px;
}

.logo {
display: block;
text-indent: -9999px;
text-transform: capitalize;
background: url(../images/logo.png) no-repeat;
height: 90px;
}

.sidebar {
height: 100%;
min-height: 100%;
width: 213px;
background: url(../images/sidebarBg.png);
box-shadow: 0 0 8px #999;
float: left;
position: absolute;
top: 0;
}

/**  MENU  **/

ul {
margin: 0;
padding: 0;
list-style: none;
}

ul li {
background: url(../images/listBg.png) bottom no-repeat;
text-indent: 50px;
}

ul li a {
color: white;
display: block;
text-decoration: none;
padding: 21px;
width: 170px;
text-shadow: 1px 1px 0 #191b20;
position:relative;
}

ul li:hover {
background: url(../images/listBgGreen.png) no-repeat;
}

ul li a:hover, ul li:hover a {
color: white;
text-shadow: 1px 1px 0 #547829;
}

ul li a.dashboard {
background: url(../images/iconDashboard.png) 25px 50% no-repeat;
}

ul li a.pages {
background: url(../images/iconPages.png) 25px 50% no-repeat;
}

ul li a.media {
background: url(../images/iconMedia.png) 25px 50% no-repeat;
}

ul li a.history {
background: url(../images/iconHistory.png) 25px 50% no-repeat;
}

ul li a.messages {
background: url(../images/iconMessages.png) 25px 50% no-repeat;
}

ul li a.settings {
background: url(../images/iconSettings.png) 25px 50% no-repeat;
}

/**  SUB MENU  **/

ul li ul.submenu {
display: block;
z-index: 500;
top: 0;
}

ul li ul.submenu li {
background: url(../images/subMenuBg.png) bottom no-repeat;
}

ul li ul.submenu li a {
background: none;
padding: 13px;
width: 189px;
}

ul li ul.submenu li.last {
border-bottom: 1px solid #54575b;
background: url(../images/subMenuBg.png) top no-repeat;
}

ul li ul.submenu li.last a {
padding: 12px;
}

ul li:hover ul.submenu li a {
text-shadow: 1px 1px 0 black;
}

ul li ul.submenu li:hover {
background: url(../images/subMenuBgHover.png) bottom no-repeat;
}

/**  PIPS  **/

.pip {
display: block;
background: url(../images/pipBg.png);
padding: 3px 12px;
position: absolute;
top: 20px;
right: 25px;
color: white;
text-align: center;
text-indent: 0;
font-size: 10px;
border-top: 1px solid #1c1f23;
border-bottom: 1px solid #4c4f56;
border-radius: 30px;
-webkit-border-radius: 30px;
-moz-border-radius: 30px;
}

ul li:hover .pip {
background: url(../images/pipBgHover.png);
border-top: 1px solid #547829;
border-bottom: 1px solid #a4ce6b;

}

/**  SEARCH  **/

.search {
background: url(../images/listBg.png) no-repeat;
padding: 18px 15px;
width: 185px;
height: 29px;
}

.search input {
width: 125px;
padding: 7px 7px 7px 35px;
border:none;
margin: 0 0 0 10px;
background: #fff url(../images/search.png) 10px 50% no-repeat;
color: #808080;

box-shadow: inset 0 0 5px #ccc;
-webkit-box-shadow: inset 0 0 5px #ccc;
-moz-box-shadow: inset 0 0 5px #ccc;

border-radius: 30px;
-webkit-border-radius: 30px;
-moz-border-radius: 30px;
}

自定义.js

$(document).ready(function() {

// Adds title attributes and classnames to list items

$("ul li a:contains('History')").addClass("dashboard").attr('title', 'Dashboard');
$("ul li a:contains('Links')").addClass("pages").attr('title', 'Pages');
$("ul li a:contains('Media')").addClass("media").attr('title', 'Media');
$("ul li a:contains('Campaigns')").addClass("history").attr('title', 'History');
$("ul li a:contains('Messages')").addClass("messages").attr('title', 'Messages');
$("ul li a:contains('Maintenance')").addClass("settings").attr('title', 'Settings');

// Add class to last list item of submenu

$("ul.submenu li:last-child").addClass("last");

$("ul li:has(ul)").hover(function(){
    $(this).find("ul.submenu").stop("true", "true").slideDown(500);
    }, function(){
    $(this).find("ul.submenu").stop("true", "true").slideUp(500);
});

});

希望这会有所帮助...谢谢

4

1 回答 1

0

固定...“显示:无;” 到菜单项

于 2012-11-06T09:58:23.383 回答