【问题标题】:Vertical sidebar nav menu collapsible with one button垂直侧边栏导航菜单可一键折叠
【发布时间】:2020-10-06 14:11:36
【问题描述】:
【问题讨论】:
标签:
javascript
menu
navigation
sidebar
【解决方案1】:
您可以删除 openbtn 按钮,只保留 HTML 中的 closebtn。
在你的 CSS 中改变这个:
.sidebar { width: 35px }
.sidebar closebtn {right: 0px}
#main { padding-left : 40px }
将您的 javascript 更改为只有带有 closebtn 的事件:
/* Set the width of the sidebar to 0 and the left margin of the page content to 0 */
let bool = false;
function closeNav() {
bool = !bool;
if (bool) {
document.getElementById("mySidebar").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
document.querySelector(".closebtn").innerHTML = "×";
} else {
document.getElementById("mySidebar").style.width = "35px";
document.getElementById("main").style.marginLeft = "0";
document.querySelector(".closebtn").innerHTML = "☰";
}
}