如何修复边栏以打开和关闭



我正试图在按下按钮后打开和关闭SideNav。然而,我只能把它关闭。当我将sideNave()函数传递给button.addEventListener("click", ... )时,不会发生任何事情。我非常感谢你的帮助!我的代码如下:

const left = document.querySelector("left");
const right = document.querySelector("right");
const button = document.querySelector("button");
button.addEventListener("click", close);
const x = true;
function close() {
document.getElementById("left").style.width = "0";
document.getElementById("right").style.width = "100%";
x = false;
}
function open() {
document.getElementById("left").style.width = "15%";
document.getElementById("right").style.width = "85%";
x = true;
}
function sideNav() {
if (x = true) {
w3_close();
} else {
open();
}
}
<!DOCTYPE html>
<html>
<head>
<title>WebPage</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="webPage.css">
<meta charset="utf-8">
<script src="https://kit.fontawesome.com/62ea397d3a.js" crossorigin="annonymous"></script>
</head>
<body>
<div class="header"></div>
<div id="left">
<button class="button">Click Me!</button>
</div>
<div id="right">
<p></p>
</div>
</body>
</html>

单击☰符号打开侧边栏(覆盖部分页面内容(。function w3_open () { document.getElementById("mySidebar").style.display = "block"; } function w3_close () {

相关内容

  • 没有找到相关文章

最新更新