gpt4 book ai didi

javascript - 按下按钮时制作全高和全宽的菜单栏

转载 作者:行者123 更新时间:2023-11-28 02:55:43 25 4
gpt4 key购买 nike

我想当我按下右上角的菜单按钮时,一些东西从左滑到右全屏(全高和全宽),其他一切都消失了。这里的问题是,如果您向下滚动然后单击菜单按钮,它不会显示它只显示在顶部。另外还有一些我不太明白的东西,高度和宽度。如果我想要覆盖整个页面或只覆盖我们可见的高度和宽度,我们该怎么做?为此,我将 100% 的高度和宽度设置为页面的可见部分,如果我们希望整个页面都被某些东西覆盖怎么办?高度和宽度如何工作?

$("#side-button").click(function(){
if ($("#side-bar").css("display") == "block"){
$("body").css("overflow","auto");
$("#side-bar").animate({width: "0%"},400,function(){
$("#side-bar").css("display","none");
});
}
else{
$("#side-bar").css("display","block").animate({width: "100%"},400,function(){
$("body").css("overflow","hidden");
});
}
});
html{
height:100%;
width:100%;
}
body{
position: relative;
height:100%;
width:100%;
}

#side-bar{
position: absolute;
width:0%;
background: black;
height: 100%;
z-index: 100;
display:none;
}

#side-button{
display:flex;
position:fixed;
right:10px;
top:10px;
z-index: 100;
width:30px;
height:30px;
justify-content: space-around;
flex-direction: column;
}

#side-button div{
width:100%;
height:4px;
background-color: gray;
display:block;
}

#side-button:hover #first{
transform: rotate(1turn);
transition: 1s transform;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bootstrap/css/bootstrap.css"/>
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="bootstrap.css"/>
</head>
<body>
<div id="side-bar">
<div class="page-header text-center header1">
<h1>THIS IS A HEADER</h1>
</div>
</div>
<div id="side-button" >
<div id="first"></div>
<div id="second"></div>
<div id="third"></div>
</div>
<div class="container" style="padding-bottom:20px;">
<div class="jumbotron ">
<h1>This is a jumbotron !</h1>
<p>The jumbotron makes a big fat div :p </p>
</div>
<div class="jumbotron ">
<h1>This is a jumbotron !</h1>
<p>The jumbotron makes a big fat div :p </p>
</div>
<div class="jumbotron ">
<h1>This is a jumbotron !</h1>
<p>The jumbotron makes a big fat div :p </p>
</div>
<div class="jumbotron ">
<h1>This is a jumbotron !</h1>
<p>The jumbotron makes a big fat div :p </p>
</div>
</div>
<script src="bootstrap.js"></script>
</body>
</html>

最佳答案

你可以将侧边栏的绝对位置更改为固定位置,该位置将相对于视口(viewport)并固定在顶部

$("#side-button").click(function(){
if ($("#side-bar").css("display") == "block"){
$("body").css("overflow","auto");
$("#side-bar").animate({width: "0%"},400,function(){
$("#side-bar").css("display","none");
});
}
else{
$("#side-bar").css("display","block").animate({width: "100%"},400,function(){
$("body").css("overflow","hidden");
});
}
});
html{
height:100%;
width:100%;
}
body{
position: relative;
height:100%;
width:100%;
}

#side-bar{
position: fixed;
top: 0;
width:0%;
background: black;
height: 100%;
z-index: 100;
display:none;
}

#side-button{
display:flex;
position:fixed;
right:10px;
top:10px;
z-index: 100;
width:30px;
height:30px;
justify-content: space-around;
flex-direction: column;
}

#side-button div{
width:100%;
height:4px;
background-color: gray;
display:block;
}

#side-button:hover #first{
transform: rotate(1turn);
transition: 1s transform;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bootstrap/css/bootstrap.css"/>
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="bootstrap.css"/>
</head>
<body>
<div id="side-bar">
<div class="page-header text-center header1">
<h1>THIS IS A HEADER</h1>
</div>
</div>
<div id="side-button" >
<div id="first"></div>
<div id="second"></div>
<div id="third"></div>
</div>
<div class="container" style="padding-bottom:20px;">
<div class="jumbotron ">
<h1>This is a jumbotron !</h1>
<p>The jumbotron makes a big fat div :p </p>
</div>
<div class="jumbotron ">
<h1>This is a jumbotron !</h1>
<p>The jumbotron makes a big fat div :p </p>
</div>
<div class="jumbotron ">
<h1>This is a jumbotron !</h1>
<p>The jumbotron makes a big fat div :p </p>
</div>
<div class="jumbotron ">
<h1>This is a jumbotron !</h1>
<p>The jumbotron makes a big fat div :p </p>
</div>
</div>
<script src="bootstrap.js"></script>
</body>
</html>

关于javascript - 按下按钮时制作全高和全宽的菜单栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46469344/

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