优化jQuery下拉菜单功能

时间:2022-11-26 11:23:13

Here's the function, which I am calling like this: $(document).ready(function(){ dropdownmenu(); });

这是函数,我这样调用:$(document).ready(function(){dropdownmenu();});

function dropdownmenu() {   
    $("#navigation ul li.upper").hover(function(){
        $("ul.submenu", this).show(400);
    },function(){
        $("ul.submenu", this).hide();
    }); 
}

How can I optimize this function, specifically preventing animation queuing and making it fire properly on page load? Any other tips would ask be welcome!

如何优化此功能,特别是防止动画排队并使其在页面加载时正常启动?欢迎任何其他提示!

Last, but not least, the markup:

最后,但并非最不重要的,标记:

    <ul>
        <li>...</li>
        <li class="upper">
            <a href="#">Example</a>
            <ul class="submenu">
                <li><a href="#">Sub-example</a></li>    
            </ul>
        </li>
        <li>...</li>

Thanks in advance!

提前致谢!

1 个解决方案

#1


All the work has already been done for you.

所有的工作都已经完成了。

Check out superfish

看看超级鱼

If you still want to roll your own then at least check the source on this plugin and also Hover with intent

如果你仍然想要自己动手,那么至少检查一下这个插件的来源,并且还有意图悬停

#1


All the work has already been done for you.

所有的工作都已经完成了。

Check out superfish

看看超级鱼

If you still want to roll your own then at least check the source on this plugin and also Hover with intent

如果你仍然想要自己动手,那么至少检查一下这个插件的来源,并且还有意图悬停