gpt4 book ai didi

javascript - 单击其他地方时关闭汉堡菜单

转载 作者:太空宇宙 更新时间:2023-11-04 01:50:29 25 4
gpt4 key购买 nike

我有一个汉堡包菜单,如果单击它本身以外的任何地方,我需要将其关闭。

这是我的 fiddle :

Fiddle

这是我的代码:

.sidenav {
height: 100%;
width: 0px;
position: fixed;
z-index: 1;
top: 0;
right: 0;
/* background-color: #111; */
background-color: white;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
}

.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: medium;
/* color: #818181; */
display: block;
transition: 0.3s;
border-bottom:1px solid black;
}

.sidenav a:hover, .offcanvas a:focus{
color: #f1f1f1;
}

.sidenav .closebtn {
border-bottom: 0px;
position: absolute;
top: 0;
right: 0;
font-size: 36px;
margin-left: 50px;
}

/* #main {
transition: margin-left .5s;
padding: 16px;
} */

@media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
.menu{z-index:1000000; font-weight:bold; font-size:0.8em; width:100%; background:#f1f1f1; position:absolute; text-align:center; font-size:12px;}
.leftFloat{
float:left;
}
::-webkit-scrollbar {
width: 0px !important; /* remove scrollbar space */
background: transparent; /* optional: just make scrollbar invisible */
}

最佳答案

试试这个:

window.onclick = function(event) {
if ($('#mySidenav').width() == 250) {
$('#mySidenav').width(0);
}
}

关于javascript - 单击其他地方时关闭汉堡菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43607383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com