Attempting to customize my personal website by making the sidebar width change when the sidebar button is clicked. I'm puzzled as to why it's not working as intended. I prefer to figure it out independently but any helpful tips would be appreciated. I'm still a beginner and don't want to get into complex changes that may be too advanced for my current level, as I've only been learning for a few weeks.
const sidebarBut = document.querySelector('.sideBarBut');
sidebarBut.addEventListener('click', animate);
function animate(){
document.querySelector('.sidebar').style.width = "400px";
}
/*--------|--------*/
.sideBarBut {
transform: scale(0.065);
background-color: black;
position: fixed;
bottom: 742.5px;
left: -235px;
cursor: pointer;
}
.sideBarBut:hover {
filter: brightness(80%);
}
.sidebarTitle {
color: white;
position: fixed;
top: -50px; /*7px*/
left: 95px;
font-size: 28px;
font-family: sans-serif;
text-decoration: underline;
text-underline-offset: 4px;
text-decoration-thickness: 2px;
}
.sidebar {
z-index: 1000;
height: 100%;
width: 0;
position: fixed;
top: 0;
left: 0;
background-color: black;
border-right: 0px solid transparent;
}
.animate {
animation-play-state: paused;
animation-name: sidebarOpen;
animation-duration: 1s;
animation-fill-mode: forwards;
}
@keyframes sidebarOpen {
0% {
width: 0;
}
100% {
width: 250px;
border-right: 2px solid white;
}
}
@keyframes sidebarClosed {
0% {
width: 250px;
}
100% {
width: 0;
border-right: 0px solid transparent;
}
}
.projectLinks {
width: 200px;
position: fixed;
top: 40px;
left: -1000px; /*20px*/
color: white;
list-style: none;
padding-left: 0;
}
.projects {
text-decoration: none;
color: inherit;
font-size: 20px;
font-family: sans-serif;
line-height: 30px;
}
.projects:hover {
color: rgb(200, 200, 200);
}
<section>
<div class="sidebar animate">
<button type="button" class="sideBarBut"><img src="img/sidebar.png"></button>
<span class="sidebarTitle">Projects</span>
<ul class="projectLinks">
<li><a class="projects" href="projects/Tic Tac Toe Project copy/index.html">Tic Tac Toe Project</a></li>
<li><a class="projects" href="projects/color changer proj/index.html">Color Changer Project</a></li>
</ul>
</div>
</section>
<script src="sidebar.js"></script>