I started this very basic UI. I want to open the shop category (in the top-left corner) with a smooth transition.
I used an onClick() function in the HTML attributes for the shop-btn element that uses the shopOpen() function in the JS code. Seems like the Javascript code is ok, but the transition does not work in the CSS code.
let shopBtn = document.querySelector(".shop-btn");
let shop = document.querySelector(".shop");
function shopOpen() {
shop.classList.toggle("shopOpenJS");
}
* {
margin: 0;
padding: 0;
font-family: arial;
}
body {
overflow: hidden;
}
.menu {
height: 100vh;
position: absolute;
top: 0;
left: 0;
}
.menu .shop-btn,
.menu .settings-btn {
width: 5vw;
}
.menu .con-shop-btn,
.menu .con-settings-btn {
height: 50vh;
padding: 0 1.3vw;
display: flex;
align-items: center;
}
.menu .con-shop-btn {
position: absolute;
top: 0;
left: 0;
background-color: #875a34;
}
.menu .shop {
height: 100vh;
position: relative;
top: 0;
right: calc(100vw - 100vw - 5vw - 1.3vw - 1.3vw);
background-color: #875a34;
transition: all 1s;
}
.menu .con-settings-btn {
position: absolute;
bottom: 0;
left: 0;
background-color: #ffffb3;
}
/*JS Classes*/
.shopOpenJS {
width: calc(100vw - 5vw - 1.3vw - 1.3vw);
}
<!DOCTYPE html>
<html>
<head>
<link type="text/css" href="style.css" rel="stylesheet">
<title></title>
</head>
<body>
<div class="menu">
<div class="con-shop-btn">
<img src="images/shop/shop.png" alt="Shop" class="shop-btn" onclick="shopOpen()">
</div>
<div class="shop"></div>
<div class="con-settings-btn">
<img src="images/settings.png" alt="Settings" class="settings-btn">
</div>
</div>
<script src="main.js"></script>
</body>
</html>