gpt4 book ai didi

javascript - 在打开侧抽屉窗口跳到 html css 中的高度零

转载 作者:太空宇宙 更新时间:2023-11-04 06:06:16 24 4
gpt4 key购买 nike

我使用 HTML CSS、bootstrap 和一点点 javascript 制作了一个侧边抽屉。我也修复了导航栏。但问题是当触发侧抽屉时,我的窗口跳到零高度。我试图找到解决方案,但没有成功。

这些是我的代码。

$(".icon-box").click(function() {
$("#sideToggleBtn").toggleClass("fa-bars fa-times");
$(".sidenav").toggleClass("sidenav-open");
$(".sidenav").css(
"width",
$(".sidenav").hasClass("sidenav-open") ? "450px" : "0px"
);
});
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1000;
top: 0;
right: 0;
background-color: $nav-Color;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
.closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
}
.sideNav-open{
width: 450px;

}
.sideNav-close{
width: 0px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav class="navbar fixed-top navbar-expand-lg navbar-light bg-white">
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav ml-auto">
<li class="nav-item hide-on-mb icon-box">
<a href="#" class="nav-link closebtn ">
<i id="sideToggleBtn" class="fas fa-bars">Menu</i>
</a>
</li>
</ul>
</div>
</nav>
<div id="mysidenav" class="sidenav">
<div class="container">
<div class="brand-wrapper">
<h1 class="brand-title">
HEllo world
</h1>
</div>
</div>
</div>

最佳答案

$(".icon-box").click(function() {
$("#sideToggleBtn").toggleClass("fa-bars fa-times");
$(".sidenav").toggleClass("sidenav-open");
$(".sidenav").css(
"width",
$(".sidenav").hasClass("sidenav-open") ? "450px" : "0px"
);
});

.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1000;
top: 0;
right: 0;
background-color: $nav-Color;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
.closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
}
.sideNav-open{
width: 450px;

}
.sideNav-close{
width: 0px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav class="navbar fixed-top navbar-expand-lg navbar-light bg-white">
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav ml-auto">
<li class="nav-item hide-on-mb icon-box">
<a href="href="javascript:void(0)" class="nav-link closebtn ">
<i id="sideToggleBtn" class="fas fa-bars">Menu</i>
</a>
</li>
</ul>
</div>
</nav>
<div id="mysidenav" class="sidenav">
<div class="container">
<div class="brand-wrapper">
<h1 class="brand-title">
HEllo world
</h1>
</div>
</div>
</div>

像这样……:)

它会为你工作谢谢......?

关于javascript - 在打开侧抽屉窗口跳到 html css 中的高度零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56833015/

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