gpt4 book ai didi

javascript - 从右侧而不是左侧切换菜单

转载 作者:行者123 更新时间:2023-11-29 18:05:44 32 4
gpt4 key购买 nike

我有一个可以从左侧切换的菜单,但我需要能够从右侧切换。不确定这是否可以从 jQuery 触发,或者可以在 CSS 中完成。当它应该只垂直滚动时,它也会在切换导航中水平滚动。

<div id="wrapper">
<!-- Sidebar -->
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li class="sidebar-brand"> <a href="#">
Entertainment
</a>

</li>
<div class="container">
<div class="row">
<div class="col-md-3">
<div class="thumbnail">
<div class="caption">
info
</div>
</div>
</div>
</div>
</div>
<div id="page-content-wrapper">
<div class="container-fluid">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="">
<ul class="nav navbar-nav navbar-left">
<li>
<img src="logo.png" height="50">
</li>
</ul>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="" height="30"></a>

</li>
</ul>
</div>
</div>
</nav> <a href="#menu-toggle" class="btn btn-default" id="menu-toggle">Toggle Menu</a>

</div>
</div>
<!-- /#page-content-wrapper -->

JSFIDDLE

最佳答案

真的很简单,您只需将所有为左侧边栏创建空间的 CSS 规则移动到右侧即可。真的就是这样。

我也将此添加到您的侧边栏包装器 overflow-x: hidden; 以在触发菜单时停止显示水平滚动条。

$("#menu-toggle").click(function (e) {
e.preventDefault();
$("#wrapper").toggleClass("toggled");
});
#menu-toggle {
float: right;
}
#wrapper {
padding-right: 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-right: 250px;
}
#sidebar-wrapper {
z-index: 1000;
position: fixed;
right: 250px;
width: 0;
height: 100%;
margin-right: -250px;
overflow-x: hidden;
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%;
position: absolute;
padding: 15px;
}
#wrapper.toggled #page-content-wrapper {
position: absolute;
margin-left: -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;
padding-right: 17%;
}
.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-right: 250px;
}
#wrapper.toggled {
padding-right: 0;
}
#sidebar-wrapper {
width: 250px;
}
#wrapper.toggled #sidebar-wrapper {
width: 0;
}
#page-content-wrapper {
padding: 20px;
position: relative;
}
#wrapper.toggled #page-content-wrapper {
position: relative;
margin-left: 0;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div id="wrapper">
<!-- Sidebar -->
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li class="sidebar-brand"><a href="#">Entertainment</a>

</li>
</div>
<div id="page-content-wrapper">
<div class="container-fluid">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="">
<ul class="nav navbar-nav navbar-left">
<li>
<img src="http://placehold.it/50x50" alt="">
</li>
</ul>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right"></ul>
</div>
</div>
</nav> <a href="#menu-toggle" class="btn btn-default" id="menu-toggle">Toggle Menu</a>

</div>
</div>
<!-- /#page-content-wrapper -->
</div>

关于javascript - 从右侧而不是左侧切换菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31393751/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com