我在网页中使用侧边栏。但是当我刷新页面时它不应该打开。现在,当我点击刷新时,它默认打开。我希望它被关闭。当用户想要打开它时,只有通过单击侧栏图标才能打开它。 下面是我的侧边栏菜单的javascript和CSS:
使用Javascript:
var toggle = true;
$(".sidebar-icon").click(function() {
if (toggle)
{
$(".page-container").addClass("sidebar-collapsed").removeClass("sidebar-collapsed-back");
$("#menu span").css({"position":"absolute"});
}
else
{
$(".page-container").removeClass("sidebar-collapsed").addClass("sidebar-collapsed-back");
setTimeout(function() {
$("#menu span").css({"position":"relative"});
}, 400);
}
toggle = !toggle;
});
CSS:
.sidebar-menu {
position: fixed;
float: left;
width: 230px;
top: 0;
left: 0;
bottom: 0;
background-color:#b52e31;
color: #aaabae;
box-shadow: 0px 0px 10px 0px rgb(58, 41, 31);
-o-box-shadow: 0px 0px 10px 0px rgb(58, 41, 31);
-webkit-box-shadow: 0px 0px 10px 0px rgb(58, 41, 31);
-moz-box-shadow: 0px 0px 10px 0px rgb(58, 41, 31);
z-index: 999;
}
a.sidebar-icon:hover{
color:#fff;
}
.page-container.sidebar-collapsed {
transition: all 100ms linear;
transition-delay: 300ms;
}
.page-container.sidebar-collapsed .left-content {
float: left;
width: 97%;
}
.page-container.sidebar-collapsed-back {
transition: all 100ms linear;
}
.page-container.sidebar-collapsed-back .left-content {
transition: all 100ms linear;
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
transition: all 0.3s ease;
float: right;
width:87%;
}
.page-container.sidebar-collapsed .sidebar-menu {
width: 65px;
transition: all 100ms ease-in-out;
transition-delay: 300ms;
}
.page-container.sidebar-collapsed-back .sidebar-menu {
width: 230px;
transition: all 100ms ease-in-out;
}
.page-container.sidebar-collapsed .sidebar-icon {
transform: rotate(90deg);
transition: all 300ms ease-in-out;
margin-right: 0em;
margin-top: -8px;
color: #fff;
background: #252525;
border-radius: 0;
}
.page-container.sidebar-collapsed-back .sidebar-icon {
transform: rotate(0deg);
transition: all 300ms ease-in-out;
}
.page-container.sidebar-collapsed .logo {
padding: 21px 0;
height: 63px;
box-sizing: border-box;
transition: all 100ms ease-in-out;
transition-delay: 300ms;
}
.page-container.sidebar-collapsed #logo {
opacity: 0;
transition: all 200ms ease-in-out;
display: none;
}
.page-container.sidebar-collapsed .down {
display: none;
}
.page-container.sidebar-collapsed-back #logo {
opacity: 1;
transition: all 200ms ease-in-out;
transition-delay: 300ms;;
}
.page-container.sidebar-collapsed #menu span {
opacity: 0;
transition: all 50ms linear;
}
.page-container.sidebar-collapsed-back #menu span {
opacity: 1;
transition: all 200ms linear;
transition-delay: 300ms;
}
我应该做出哪些改变?帮帮我