开发者

Compacting jQuery Dropdown Menu Code

How would I compact this jQuery drop down menu code? I know you can use the Superfish plugin for this, but I'm more interested in learning the programming skills on this one. I know it would involve changing the "#navabout" IDs to something like "#Nav1" and the dropdown IDs to match, like "#drop1" and then running an array, possibly?

    $('#navabout').hover(
    function () {
        $('#dropabout').show();
    },
    function () {
        $('#dropabout').hide();
});

$('#navnews').hover(
    function () {
        $('#dropnews').show();
    },
    function () {
        $('#dropnews').hide();
});

$('#navgroups').hover(
    function () {
        $('#dropgroups').show();
    },
    function () {
        $('#dropgroups').hide();
});

$('#navemployee')开发者_开发百科.hover(
    function () {
        $('#dropemployee').show();
    },
    function () {
        $('#dropemployee').hide();
});

$('#navtools').hover(
    function () {
        $('#droptools').show();
    },
    function () {
        $('#droptools').hide();
});


assign a "menu" class to all your menus.

then do

$('.yourClass').hover(
    function () {
        $(this).show();
    },
    function () {
        $(this).hide();
});


You can handle this without JavaScript. If the menu is running off the "Suckerfish" style and you don't need drop-downs on IE6 and below all you need to use is :hover.

#menu li:hover ul { 
    left: auto;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜