我正在制作一个导航按钮,它可以从3行转换为x
var anchor = document.querySelectorAll('button');
[].forEach.call(anchor, function(anchor) {
var open = false;
anchor.onclick = function(event) {
event.preventDefault();
if (!open) {
this.classList.add('close');
open = true;
} else {
this.classList.remove('close');
open = false;
}
}
});Run Code Online (Sandbox Code Playgroud)
html,
body {
height: 100%;
}
body {
background-color: white;
font-family: "Source Sans pro", sans-serif;
}
#mbtn {
display: inline-block;
margin: 0 1em;
border: none;
background: none;
}
#mbtn span {
display: block;
}
.lines-button {
padding: 2rem 1rem;
transition: .3s;
cursor: pointer;
/* */
} …Run Code Online (Sandbox Code Playgroud)