Reputation: 33
lets say i have a code on masterpage for a menu bar
here's the populating menu bar code
private void PopulateMenu()
{
List<BOMsMenu> ListMenuParent = new List<BOMsMenu>();
List<BOMsMenu> ListMenuChild = new List<BOMsMenu>();
DACommon common = new DACommon();
ListMenuParent = common.GetParentMenu(UserLogin.AuthorityAccessID, UserLogin.UserName);
string innerHTML = string.Empty;
if (common.MsgCode == 0)
{
common = new DACommon();
List<int> ListParentID = (from a in ListMenuParent
where a.IsParent == true
select a.IDMenu).ToList();
ListMenuChild = common.GetChildMenu(ListParentID, UserLogin.AuthorityAccessID);
if (common.MsgCode == 0)
{
for (int i = 0; i < ListMenuParent.Count; i++)
{
if (!ListMenuParent[i].IsParent)
{
innerHTML += "<li><a href=\"" + ListMenuParent[i].FormName + "\" class=\"no-sub\"> " + ListMenuParent[i].MenuName + "</a></li>" + Environment.NewLine;
}
else
{
innerHTML += "<li class=\"has-sub\"><a href=\"" + ListMenuParent[i].FormName + "\">" + ListMenuParent[i].MenuName + "<span class=\"sub-arrow\"></span></a>" + Environment.NewLine + "<ul>" + Environment.NewLine;
for (int j = 0; j < ListMenuChild.Count; j++)
{
if (ListMenuChild[j].IDParent == ListMenuParent[i].IDMenu)
{
innerHTML += "<li class=\"sub-menu\"><a href=\"" + ListMenuChild[j].FormName + "\">" + ListMenuChild[j].MenuName + "</a></li>" + Environment.NewLine;
}
}
innerHTML += "</ul>" + Environment.NewLine + "</li>" + Environment.NewLine;
}
}
}
divMenuBar.InnerHtml = innerHTML;
}
}
the aspx html code
<div class="menu-bar-wrap" id="wrap-menu-bar">
<div class="menu-bar">
<ul class="menu-bar-ul" runat="server" id="divMenuBar">
</ul>
</div>
</div>
and the css
.divMenuBarBlock {
float:left;
width:100%;
height:100%;
}
.menu-bar {
float:left;
min-height:100%;
width:100%;
height:100%;
background: #CFCFC4;
}
.menu-bar a{
display:block;
padding: 10px 10px 10px 10px;
text-decoration:none;
border-bottom: 1px dotted gray;
color: #000;
letter-spacing: .002em;
text-transform: uppercase;
font-family:Helvetica, Arial, sans-serif;
font-style:normal;
font-size:medium;
}
.menu-bar li{
list-style:none;
}
.menu-bar ul li ul li:hover {
background:gray;
}
.menu-bar-ul ul {
display:none;
}
.no-sub:hover {
background:gray;
}
.sub-arrow {
margin-left:15px;
}
.menu-bar-ul li.click ul {
display:block;
}
.menu-bar .sub-arrow:after {
content:'\203A';
float:right;
margin-right:10px;
transform:rotate(90deg);
-webkit-transform:rotate(90deg);
-moz-transform:rotate(90deg);
}
.menu-bar li.click .sub-arrow:after {
content: '\2039';
}
.menu-bar-ul ul a:before {
content:'\203A';
margin-right:10px;
}
script for run the jquery
$(document).ready(function (e) {
$('.has-sub').click(function () {
$(this).toggleClass('click');
});
$('.has-sub li a').click(function (e) {
e.stopPropagation();
});
});
and how i can delay the toggle class, for making the animation toggle of the sub menu more smooth?
Upvotes: 0
Views: 1395
Reputation: 50346
A toggleClass accepts following parameters
( className [, switch ] [, duration ] [, easing ] [, complete ] )
So delay can be added like this
$(this).toggleClass('click',2000);
where the number 2000
is the duration which determine how long the animation will run.
Upvotes: 2