相关疑难解决方法(0)

单击任何地方但菜单时,jQuery隐藏下拉列表

我正在尝试将其设置为当您单击按钮时显示我的下拉菜单,并且当您单击除下拉菜单之外的任何位置时隐藏该隐藏菜单.

我有一些代码正常工作,当你单击菜单时没有关闭,但是当你关闭菜单时单击文档,它会显示菜单,所以无论你在哪里点击它都会不断切换.

$(document).click(function(event) {
    if ($(event.target).parents().index($('.notification-container')) == -1) {
        if ($('.notification-container').is(":visible")) {
            $('.notification-container').animate({
                "margin-top": "-15px"
            }, 75, function() {
                $(this).fadeOut(75)
            });
        } else {
            //This should only show when you click: ".notification-button" not document
            $('.notification-container').show().animate({
                "margin-top": "0px"
            }, 75);
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery menu javascript-events

23
推荐指数
4
解决办法
4万
查看次数

标签 统计

javascript ×1

javascript-events ×1

jquery ×1

menu ×1