需要从悬停到单击的帮助更改菜单



---原始悬停代码---

function bind_dropdown() {
    $('div#quick_nav div.search_dropdown').on('hover', function() {
        var thisid = $(this).attr('id').split('_');
        var this_action = thisid[1];
        var this_width = 950;
        var add_class = 'dropdown_full';
        if(this_action == 4) {
            this_width = 200;
            add_class = 'dropdown_small';
        }
        if($('div#quick_nav div#dropdown_'+escape(this_action)).is(':visible')) {
            $('div#quick_nav div#dropdown_'+escape(this_action)).addClass(add_class).slideUp(100);
        }
        else{
            $('div#quick_nav div.dropdown').hide();
            $('div#quick_nav div#dropdown_'+escape(this_action)).addClass(add_class).slideDown(100).width(this_width);
        }
        return false;
    });
}

- - 结束原始代码---

我确实尝试更改悬停以单击。但是,关闭您现在必须再次单击菜单图标的菜单。任何帮助将不胜感激。我希望能够单击以显示菜单,当鼠标从菜单上移动时,它将自动关闭。

预先感谢您

J

使用以下代码

function bind_dropdown() {
    $('div#quick_nav div.search_dropdown').on('click', function() {
        var thisid = $(this).attr('id').split('_');
        var this_action = thisid[1];
        var this_width = 950;
        var add_class = 'dropdown_full';
        if(this_action == 4) {
            this_width = 200;
            add_class = 'dropdown_small';
        }
        if($('div#quick_nav div#dropdown_'+escape(this_action)).is(':visible')) {
            $('div#quick_nav div#dropdown_'+escape(this_action)).addClass(add_class).slideUp(100);
        }
        return false;
    }).on("mouseleave", function() {
        var thisid = $(this).attr('id').split('_');
        var this_action = thisid[1];
        var this_width = 950;
        var add_class = 'dropdown_full';
        if(this_action == 4) {
            this_width = 200;
            add_class = 'dropdown_small';
        }
        $('div#quick_nav div.dropdown').hide();
        $('div#quick_nav div#dropdown_'+escape(this_action)).addClass(add_class).slideDown(100).width(this_width);
    });
}

最新更新