gpt4 book ai didi

javascript - 第一次隐藏切换栏

转载 作者:太空宇宙 更新时间:2023-11-03 23:10:24 24 4
gpt4 key购买 nike

我有一个切换菜单的代码,当我点击切换时,侧面菜单被隐藏,当我再次点击切换时,它会出现。但我想稍微改变一下,目前第一次加载页面时,默认情况下会出现侧边菜单,当我点击切换时它会消失,我希望第一次加载页面时出现侧边菜单应该隐藏,当我点击切换时它应该出现。谁能告诉我怎么做

<div id="wrapper">
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li>
<a href="#">Dashboard</a>
</li>
</ul>
</div>

<a href="#menu-toggle" class="btn btn-default" id="menu-toggle">toggle</a>
</div>
<script src="js/jquery-1.11.0.js"></script>

<!-- Menu Toggle Script -->
<script>
$("#menu-toggle").click(function(e) {
e.preventDefault();
$("#wrapper").toggleClass("toggled");
});
</script>

用于整个切换的 css

#wrapper {
padding-left: 0;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}

#wrapper.toggled {
padding-left: 250px;
}

#sidebar-wrapper {
z-index: 1000;
position: fixed;
left: 250px;
width: 0;
height: 100%;
margin-left: -250px;
overflow-y: auto;
background: #000;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}

#wrapper.toggled #sidebar-wrapper {
width: 250px;
}

#page-content-wrapper {
width: 100%;
padding: 15px;
}

#wrapper.toggled #page-content-wrapper {
position: absolute;
margin-right: -250px;
}

/* Sidebar Styles */

.sidebar-nav {
position: absolute;
top: 0;
width: 250px;
margin: 0;
padding: 0;
list-style: none;
}

.sidebar-nav li {
text-indent: 20px;
line-height: 40px;
}

.sidebar-nav li a {
display: block;
text-decoration: none;
color: #999999;
}

.sidebar-nav li a:hover {
text-decoration: none;
color: #fff;
background: rgba(255,255,255,0.2);
}

.sidebar-nav li a:active,
.sidebar-nav li a:focus {
text-decoration: none;
}

.sidebar-nav > .sidebar-brand {
height: 65px;
font-size: 18px;
line-height: 60px;
}

.sidebar-nav > .sidebar-brand a {
color: #999999;
}

.sidebar-nav > .sidebar-brand a:hover {
color: #fff;
background: none;
}

@media(min-width:768px) {
#wrapper {
padding-left: 250px;
}

#wrapper.toggled {
padding-left: 0;
}

#sidebar-wrapper {
width: 250px;
}

#wrapper.toggled #sidebar-wrapper {
width: 0;
}

#page-content-wrapper {
padding: 20px;
}

#wrapper.toggled #page-content-wrapper {
position: relative;
margin-right: 0;
}
}

最佳答案

绑定(bind)后可以触发点击事件:

$("#menu-toggle").click(function(e) {
e.preventDefault();
$("#wrapper").toggleClass("toggled");
}).click(); //click triggered....

关于javascript - 第一次隐藏切换栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32817729/

24 4 0