gpt4 book ai didi

javascript - 我如何使用 javascript 和 css 使栏出现和消失

转载 作者:行者123 更新时间:2023-11-28 05:01:47 25 4
gpt4 key购买 nike

我想制作一个栏,当我点击一个按钮时出现,当我点击屏幕的其余部分时消失,但我无法让它工作。

HTML:

<div class="header">
<nav class="navbar navbar-default navbar-fixed-top">
<a class="bar" href="">
<i onclick="openbar();" class="glyphicon glyphicon-align-justify"></i>
</a>
<div class="container">
<div class="left">
<h2 class="invisible">hola</h2>
</div>
<div class="center">
<h1 class="title">Project Ignite</h1>
</div>
<div class="right">
<h2 class="invisible">hola</h2>
</div>
</div>
</nav>
</div>

<div class="body">
<div class="container"></div>
<div class="bar" id="bar"></div>
</div>

Javascript:

function openbar() {

document.getElementById('bar').classList.toggle('openbar');

}

CSS:

.bar {
position:absolute;
float: left;
background-color: #F89406;
width: 0%;
height: 100%;
}
.openbar {
position:absolute;
float: left;
background-color: #F89406;
width: 12%;
height: 100%;
}
.bar i {
color: white;
font-size: 32px;
float: left;
position: absolute;
padding-top: 16px;
padding-left: 16px;
}

.icon-bar {
width: 120px;
height: 120px;
color: red;
}

我该怎么做才能解决我的问题?提前谢谢你,molocoPS:我是 JS 新手

最佳答案

这应该有效:

function openbar() {
document.getElementById('bar').classList.toggle('openbar');
}
.bar {
position: absolute;
float: left;
background-color: #F89406;
width: 12%;
height: 10%;
}
#bar {
display: none;
}
.openbar {
display: block !important;
}
.bar i {
color: white;
font-size: 32px;
float: left;
position: absolute;
padding-top: 16px;
padding-left: 16px;
}
.icon-bar {
width: 120px;
height: 120px;
color: red;
}
<div class="header">
<nav class="navbar navbar-default navbar-fixed-top">
<a class="bar">
<i onclick="openbar();" class="glyphicon glyphicon-align-justify">click me</i>
</a>
<div class="container">
<div class="left">
<h2 class="invisible">hola</h2>
</div>
<div class="center">
<h1 class="title">Project Ignite</h1>
</div>
<div class="right">
<h2 class="invisible">hola</h2>
</div>
</div>
</nav>
</div>
<div class="body">
<div class="container">
</div>
<div class="bar" id="bar">

</div>
</div>

关于javascript - 我如何使用 javascript 和 css 使栏出现和消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40062159/

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