As you can see in the below code snippet I have a vertical sidebar that can become wider when a TOGGLE button is clicked. The Sidebar eases in with an animation and additionally displays the description text when the sidebar is wide. I think I achieved all of this properly.
My concern is more about my code. It doesn't feel right. Is there anyway I can do this all with simply adding and removing css classes?
Additionally, I would like advice on the way I am using delay to make sure when the extra description text appears it doesn't look horrible.
var menuSize = 'Small';
$(".js-menu-toggle").click(function(e) {
e.preventDefault();
if (menuSize == 'Small') {
$('#sidebar').css('width', '180px');
$('#content-wrapper').css('margin-left', '180px');
$('#sidebar').css('-webkit-transition', 'all 0.3s ease');
$('#sidebar').css('-moz-transition', 'all 0.3s ease');
$('#sidebar').css('-ms-transition', 'all 0.3s ease');
$('#sidebar').css('-o-transition', 'all 0.3s ease');
$('#sidebar').css('transition', 'all 0.3s ease');
$('#app-wrapper').css('-webkit-transition', 'all 0.3s ease');
$('#app-wrapper').css('-moz-transition', 'all 0.3s ease');
$('#app-wrapper').css('-ms-transition', 'all 0.3s ease');
$('#app-wrapper').css('-o-transition', 'all 0.3s ease');
$('#app-wrapper').css('transition', 'all 0.3s ease');
$('.menu-item-desc').delay(120).show(0);
menuSize = 'Large'
} else {
$('#sidebar').css('width', '50px');
$('#content-wrapper').css('margin-left', '50px');
$('#sidebar').css('-webkit-transition', 'all 0.3s ease');
$('#sidebar').css('-moz-transition', 'all 0.3s ease');
$('#sidebar').css('-ms-transition', 'all 0.3s ease');
$('#sidebar').css('-o-transition', 'all 0.3s ease');
$('#sidebar').css('transition', 'all 0.3s ease');
$('#content-wrapper').css('-webkit-transition', 'all 0.3s ease');
$('#content-wrapper').css('-moz-transition', 'all 0.3s ease');
$('#content-wrapper').css('-ms-transition', 'all 0.3s ease');
$('#content-wrapper').css('-o-transition', 'all 0.3s ease');
$('#content-wrapper').css('transition', 'all 0.3s ease');
$('.menu-item-desc').hide();
menuSize = 'Small'
}
});
html,
body {
height: 100vh;
}
#sidebar {
position: fixed;
top: 0;
left: 0;
width: 50px;
height: 100%;
z-index: 2;
background-color: #102027;
color: #fff;
}
#sidebar ul {
list-style: none;
padding: 0;
margin: 0;
}
#sidebar a {
color: #fff;
}
#content-wrapper {
position: relative;
top: 0;
left: 0;
overflow: hidden;
height: 100%;
margin-left: 50px;
padding-top: 100px;
padding-bottom: 30px;
}
#header-wrapper {
position: absolute;
top: 0;
left: 0;
z-index: 2;
overflow: hidden;
width: 100%;
height: 100px;
}
#header {
width: 100%;
height: 50px;
background-color: #fff;
}
#subheader {
width: 100%;
height: 50px;
background-color: #37474f;
color: #fff;
clear: right;
}
#content {
position: relative;
top: 0;
left: 0;
overflow: auto;
z-index: 1;
width: 100%;
height: 100%;
padding-top: 15px;
padding-bottom: 15px;
}
#footer {
position: absolute;
bottom: 0;
left: 0;
z-index: 2;
overflow: hidden;
width: 100%;
height: 30px;
line-height: 30px;
border-top: solid 1px #cfcfcf;
background: #fff;
}
.menu-item-desc {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="sidebar">
<a class="js-menu-toggle" href="#">TOGL</a>
<ul>
<li>Item 1<span class="menu-item-desc"> - Item 1 Desc</span></li>
<li>Item 2<span class="menu-item-desc"> - Item 2 Desc</span></li>
<li>Item 3<span class="menu-item-desc"> - Item 3 Desc</span></li>
</ul>
</div>
<div id="content-wrapper">
<div id="header-wrapper">
<div id="header" class="container-fluid">Header</div>
</div>
<div id="content" class="container-fluid">PRIMARY CONTENT</div>
</div>