Here is a JSFiddle of an accordion menu that i've done. I have used :before
to add the icons.
My question is, is there a better way to Add different icon to each li
item?
My code is as follows:
HTML Structure:
<ul id="accordion">
<li><div id="profile">Profile</div></li>
<li><div id="messages">Messages</div>
<ul class="submenu">
<li>Inbox</li>
<li>Sent</li>
<li>Drafts</li>
</ul>
</li>
<li><div id="settings">Settings</div></li>
<li><div id="logout">Logout</div></li>
</ul>
CSS:
body {
background-image: url(http://subtlepatterns.subtlepatterns.netdna-cdn.com/patterns/tiny_grid.png);
}
ul{
list-style-type:none;
padding:0;
margin:0;
}
#accordion{
margin: 20% auto 80% auto;
width:200px;
height:auto;
background-color:#212830;
border-radius:5px;
color: #BECEDB;
font-family: 'Maven Pro', sans-serif;
border: 1px solid #191E24;
box-shadow: 0px 0px 5px 2px #666666;
}
#accordion > li > div{
background-color:#383C48;
font-weight:700;
-moz-box-shadow:inset 0 1px 1px -1px #A1B3C9;
-webkit-box-shadow:inset 0 1px 1px -1px #A1B3C9;
box-shadow:inset 0 1px 1px -1px #A1B3C9;
border-bottom:1px solid #191E24;
}
#accordion > li > div, #accordion > li > ul > li{
padding:10px 15px;
}
#accordion li{
cursor:pointer;
}
#accordion > li:first-child >div{
border-radius: 5px 5px 0 0;
}
#accordion > li:last-child >div{
border-radius: 0 0 5px 5px;
}
#profile:before,
#messages:before,
#settings:before,
#logout:before,
.submenu>li:before
{
font-family:FontAwesome;
}
#profile:before{
content:"\f007 ";
}
#messages:before{
content:"\f0e0";
}
#settings:before{
content:"\f013";
}
#logout:before{
content:"\f08b";
}
.submenu li:before{
content:"\f0da"
}
#accordion *:before{
margin-right:10px;
}
.submenu li{
margin-left:10px;
}
JS code: (No problem with this)
$("#accordion > li > div").click(function(){
if(false == $(this).next().is(':visible')){
$('#accordion ul').slideUp(400);
}
$(this).next().slideToggle(300);
});
$('#accordion ul:eq(0)').show();
Also I would like to know if there are other areas this can be optimized.
Thank you