javascript - Css / Jquery 切换左栏以从右侧而不是左侧打开
问题描述
我有这个 css 从左边切换左栏(因为它是不应该做的)
$('#toggleleft').on('click', function(e) {
e.preventDefault();
$('.leftbar').toggleClass('open');
}
);
.wrapper {
position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
height: 100%;
width: 100%;
background: blue;
margin: auto;
overflow: hidden;
}
.leftbar {
position: relative;
background: green;
width: 300px;
-webkit-transition-duration: .3s;
transition-duration: .3s;
margin-left: -300px;
-webkit-border-top-left-radius: 4px;
-webkit-border-bottom-left-radius: 4px;
-moz-border-radius-topleft: 4px;
-moz-border-radius-bottomleft: 4px;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
.leftbar.open {
margin-left: 0;
}
.content {
background: red;
min-width: 0;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="wrapper">
<div class="leftbar"></div>
<div class="content">
<a id="toggleleft" href="#">toggle left</a>
</div>
</div>
正如您所看到的,它是一个工作代码,但我需要修改 css 所以......我的问题是,如何更改 css 以便它从右侧打开?
解决方案
margin-right: -300px;
在规则中使用for.leftbar
和margin-right: 0px;
in.leftbar.open
推荐阅读
- mysql - SQL 任务,如果产品在给定月份没有销售,则在本月显示 0
- javascript - Fullcalendar 事件颜色 MySQL
- playframework - 播放框架“runProd”不接受自定义配置文件
- c++ - 从 ostringstream 读取/写入会更改原始数据
- python - 使用 Dockerfile RUN 而不是 CMD 传递环境变量
- java - 如何启用firebase离线数据并将数据传递给recyclerview适配器?
- python - 是否可以在 Django 模板中过滤“相关字段”?
- php - 如果在数据库中找不到条目,我如何获得所需的值
- jquery - 用户单击链接并重定向时如何保持子菜单不折叠
- c# - 如何转换 ReadOnlyMemory
到只读存储器