Я пытаюсь сделать так, чтобы мое раскрывающееся меню показывалось, когда вы нажимаете кнопку, и скрывается, когда вы нажимаете где-либо, кроме раскрывающегося меню.
У меня есть какой-то код, который не закрывается, когда вы нажимаете меню, однако, когда вы нажимаете на документ, когда меню закрыто, оно отображает меню, поэтому оно непрерывно переключается независимо от того, где вы нажимаете.
$(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);
}
}
});