закрытие мобильного меню при клике вне его
Есть мобильное меню. Сделал простое условие закрытия данного меню при клике вне его, но проблема в том, что при клике на "крестик", меню не закрывается. Пробовал по всякому уже.. Может у кого есть какие нибудь догадки? Спасибо.
$(document).ready(function () {
$(document).mouseup(function (e) {
var container = $(".header_content_one_menu");
if (container.has(e.target).length === 0){
$('#header_menu_adaptive').prop('checked', false);
}
});
});
#header_menu_adaptive:checked ~ .header_menu_adaptive_button > span {
transform: rotate(45deg);
visibility: hidden;
}
#header_menu_adaptive:checked ~ .header_menu_adaptive_button> span::before {
top: 0;
transform: rotate(0);
visibility: visible;
}
#header_menu_adaptive:checked ~ .header_menu_adaptive_button > span::after {
top: 0;
transform: rotate(90deg);
visibility: visible;
}
#header_menu_adaptive:checked ~ .header_content_one_menu {
visibility: visible;
left: 0;
}
.header_menu_adaptive_button {
display: flex;
align-items: center;
width: 50px;
height: 50px;
cursor: pointer;
z-index: 3;
padding: 0 20px 0 0;
}
.header_menu_adaptive_button > span,
.header_menu_adaptive_button> span::before,
.header_menu_adaptive_button > span::after {
display: flex;
justify-content: center;
width: 50px;
position: absolute;
text-transform: uppercase;
color: #B72A20;
font-family: RobotoCondensed;
letter-spacing: 2.4px;
transition-duration: .25s;
font-size: 16px;
z-index: 11112;
}
.header_menu_adaptive_button > span::before {
content: '';
bottom: 29px;
width: 50px;
height: 2px;
background-color: #B72A20;
transition-duration: .25s;
}
.header_menu_adaptive_button > span::after {
content: '';
top: 28px;
width: 50px;
height: 2px;
background-color: #B72A20;
transition-duration: .25s;
}
.header_content_one_menu {
display: grid;
grid-row-gap: 20px;
position: absolute;
visibility: hidden;
top: 0;
border-radius: 0 0 0 0;
left: -100%;
width: 100%;
height: auto;
margin: 0;
padding: 30px 0 30px 0;
background-color: #333333;
transition-duration: .25s;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="header_menu_adaptive" type="checkbox">
<label class="header_menu_adaptive_button" for="header_menu_adaptive">
<span>меню</span>
</label>
<ul class="header_content_one_menu">
<li>111</li>
<li>222</li>
<li>333</li>
<li>444</li>
<li>555</li>
</ul>