【问题标题】:jquery toggleclass delay timejquery toggleclass 延迟时间
【发布时间】:2017-05-09 03:51:19
【问题描述】:

假设我在母版页上有一个菜单栏的代码

这是弹出菜单条码

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;


        }
    }

aspx html 代码

<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>

和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;
}

运行 jquery 的脚本

$(document).ready(function (e) {
    $('.has-sub').click(function () {
        $(this).toggleClass('click');
    });
    $('.has-sub li a').click(function (e) {
        e.stopPropagation();
    });
}); 

以及如何延迟切换类,以使子菜单的动画切换更流畅?

【问题讨论】:

标签: javascript jquery html css


【解决方案1】:

toggleClass 接受以下参数

( className [, switch ] [, duration ] [, easing ] [, complete ] )

所以可以像这样添加延迟

$(this).toggleClass('click',2000);

其中的数字2000 是确定动画将运行多长时间的持续时间。

【讨论】:

  • @NewbieProgrammer 乐于提供帮助
猜你喜欢
  • 1970-01-01
  • 2022-01-19
  • 2011-02-12
  • 2013-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-22
  • 2011-03-26
相关资源
最近更新 更多