0
I am creating a page, the goal is whenever I click to expand the menu the resolution of the div decrease a little and whenever I click again this resolution increase pro normal size.
My logic was the following: I put an onclick on the label that triggers a function that checks the resolution that is in the id, if it equals 100% it will put to 76.5% (because it would indicate that the menu was closed and would open) and if I was different from 100% it would put at 100% (It would indicate that the menu was open and would close)
But something unexpected happened, it is totally the opposite, when I click to open the menu it increases the div and when I click to close it decreases, where I am missing?
HTML
<body>
<input type="checkbox" id="check">
<label id="icone" for="check" onclick="resolucao()"><img src="../../icones/menu.png"></label>
<div class="barrasuperior">
</div>
<div class="barra">
<div id="caracteristicas">
</div>
<nav>
<input type="text" placeholder="Pesquise uma aula" class="pesquisar">
<a href=""><div class="link">Módulo 1:</div></a>
<a href=""><div class="link">Módulo 2:</div></a>
<a href=""><div class="link">Módulo 3:</div></a>
<a href=""><div class="link">Módulo 4:</div></a>
<a href=""><div class="link">Módulo 5:</div></a>
</nav>
</div>
<div id="conteudo">
<div class="opcoes">
<div class="anterior">
<a href="" style="color:white;"><span>Aula Anterior</span></a>
</div>
<div class="proximo">
<a style="color:white;" href=""><span>Próxima Aula</span></a>
</div>
</div>
<div class="aula">
</div>
<h2 id="titulo">TITULO DA AULA</h2>
<button onclick="materiais()">Materiais da Aula</button>
</div>
<script>
function materiais(){
document.location.href = 'https://google.com/'
}
</script>
</body>
CSS
* {
margin: 0;
padding: 0;
}
body {
background-color:#f9f9f9;
}
a {
text-decoration: none;
}
.barrasuperior {
width: 100%;
height:60px;
background-color: black;
}
#check {
display:none;
}
#icone {
cursor:pointer;
padding:15px;
position: absolute;
z-index: 1;
}
.barra {
background-color:black;
height:100%;
width: 300px;
position: absolute;
transition: all .2s linear;
left: -300px;
}
nav {
width: 100%;
position: absolute;
top: 60px;
}
nav a {
text-decoration: none;
}
.pesquisar {
width: 284px;
margin-top:10px;
margin-bottom:10px;
}
.link {
background-color:#494950;
padding:20px;
font-family: Arial, Helvetica, sans-serif;
font-size: 12pt;
transition: all .2s linear;
color: #f4f4f9;
border-bottom: 2px solid #222;
}
.link:hover {
background-color: #050542;
}
#check:checked ~ .barra {
transform: translateX(300px)
}
#check:checked ~ .barra nav a .link {
opacity: 1;
margin-top:0;
}
#conteudo {
width:100%;
height:500px;
background-color:#191919;
float:right;
}
#conteudo2 {
width:76.5%;
height:500px;
background-color:#191919;
float:right;
}
.opcoes {
width:100%;
border:1px solid #2c2c2c;
display:flex;
justify-content:space-between;
}
.anterior {
display:inline;
padding:10px;
}
.proximo {
display:inline;
padding:10px;
}
.aula {
width: 700px;
height: 300px;
margin:20px auto;
border:1px solid #0b47ca;
box-shadow:0px 0px 5px #28bcf4;
}
#titulo {
color: #f3f3f3;
text-align: center;
text-transform: uppercase;
font-weight: lighter;
font-size: 1.2rem;
font-family: inherit;
}
button{
display:block;
margin:20px auto;
padding:15px 40px;
background-image: linear-gradient(198deg,#28bcf4,#0b47ca);
border-radius: 30px;
border:none;
color:white;
text-transform: uppercase;
font-weight: bold;
font-family: 'Titillium Web';
font-size:12px;
cursor:pointer;
}
JS
function resolucao(){
var reso = document.getElementById('conteudo').style.width
comparar = '100%'
if(reso == comparar){
document.getElementById('conteudo').style.width = '76.5%'
} else {
document.getElementById('conteudo').style.width = '100%'
}
}
I think you got that phrase mixed up
e se estive-se diferente de 100% ele colocaria em 100%
or was that right?– hugocsl
Hi Hugo, that’s right but I don’t think I could explain it very well, I meant like this: The default value of width is 100%, when you open the page it is already at this value, so when you click the first time would give True because 100% is equal to 100% and it would be 76.5%. Already with the open menu (in this case the standard would be 76.5%) it would be different from 100%, then it would put back in the 100% because this would symbolize the closed menu again
– mikestudante