【发布时间】:2022-01-04 15:47:46
【问题描述】:
几天前我开始创建网站,现在我遇到了第一个真正的问题:
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
function myLama(x) {
x.classList.toggle("change");
}
.dropbtn {
display : inline-block;
margin-right : 6% !important;
float : right !important;
padding-top : 0px !important;
margin-top : -40px !important;
cursor : pointer;
}
.dropdown {
position : relative;
display : inline-block;
float : right;
top : 40px;
right : 6%;
}
.dropdown-content {
display : none;
min-width : 14px;
box-shadow : 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index : 1;
border-radius : 25px;
width : 10%;
float : right;
margin-right : 33px;
}
.dropdown-content a {
color : white;
padding : 12px 16px;
text-decoration : none;
display : block;
border : 2px solid white;
border-radius : 25px;
font-size : 20px;
margin-top : 5px;
}
.dropdown-content a : hover {
background-color : #ffffff10;
backdrop-filter : blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.show {
display : block;
}
.btn {
-ms-touch-action : manipulation;
touch-action : manipulation;
cursor : pointer;
-webkit-user-select : none;
-moz-user-select : none;
-ms-user-select : none;
user-select : none;
}
.komorka {
background-color : #ffffff10;
backdrop-filter : blur(12px);
-webkit-backdrop-filter: blur(12px);
min-width : 110px;
box-shadow : 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index : 1;
border-radius : 25px;
width : 10%;
border : 2px solid white;
color : white;
margin-left : auto;
margin-right : auto;
}
<div class="dropbtn" onclick="myLama(this); myFunction()">
<div onclick="myFunction()">
<div class="bar1" ></div>
<div class="bar2" ></div>
<div class="bar3" ></div>
</div>
</div>
<div id="myDropdown" class="dropdown-content">
<a href="#" class="komorka">Link 1</a>
<a href="#" class="komorka">Link 2</a>
<a href="#" class="komorka">Link 3</a>
</div>
</div>
我想解决,谁能帮帮我?
【问题讨论】:
-
您的代码不会产生您描述的输出或图像中的内容。请编辑您的帖子以创建您描述的minimal reproducible example。请删除与您的问题没有直接关系的任何内容(css)。
-
如果您使用的是Chrome,您可以右键单击>检查单击不起作用的位置,然后您可以检查该位置是否真的是div。也许 div 上有一个元素拦截了点击(有些元素会这样做,即使没有为其分配 onclick)。
标签: javascript html css menu toggle