【发布时间】:2019-08-21 07:10:12
【问题描述】:
我编写了这个脚本。如果窗口大小小于 1000 像素,则可以展开菜单点。 但是,如果您折叠菜单点并增加窗口大小,菜单点仍会保持隐藏状态。我不让它再次淡入它们。
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<nav>
<h2>S U P E R</h2>
<button class="button" onclick="fold()">FOLD</button>
<div id="folding">
<a>Under Construction 1</a><br>
<a>Under Construction 2</a><br>
<a>Under Construction 3</a><br>
<a>Under Construction 4</a><br>
</div>
</nav>
</body>
</html>
CSS:
#folding {
display: block;
}
.button {
display: none;
}
@media screen and (max-width: 1000px) {
.button {
display: block;
}
#folding {
display: none;
}
body {
background-color: red;
}
}
JS:
function fold() {
var x = document.getElementById("folding");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
【问题讨论】:
标签: javascript css mobile media-queries screen