Good morning! I've built several blocks with a div
that through JavaScript, it interacts as if you were opening a drawer (block) with a click and closing it with two clicks through a function.
However, when you open one block and the other at the same time, the two open on the same page, taking the visual style of the HTML / CSS structure. And when all of them open at the same time, there is a disorganized structure, because I have defined that the 5 blocks (guides) occupy a width of 4% and the "drawer" that would be opened, had the width of 80%. This error happens because the maximum width of the page goes up to 100% and all open windows, exceeds the defined width, leaving all the blocks one underneath the other.
function Exibir1() {
document.getElementById("div01").style.display = "block";
}
function Ocultar1(){
document.getElementById("div01").style.display = "none";
}
function Exibir2() {
document.getElementById("div02").style.display = "block";
}
function Ocultar2(){
document.getElementById("div02").style.display = "none";
}
function Exibir3() {
document.getElementById("div03").style.display = "block";
}
function Ocultar3(){
document.getElementById("div03").style.display = "none";
}
function Exibir4() {
document.getElementById("div04").style.display = "block";
}
function Ocultar4(){
document.getElementById("div04").style.display = "none";
}
function Exibir5() {
document.getElementById("div05").style.display = "block";
}
function Ocultar5(){
document.getElementById("div05").style.display = "none";
}
#blockpop{
background-color: lightgray;
width: 4%;
height: 300px;
float: left;
border: 1px solid;
padding-top: 9%;
padding-left: 1.9%;
}
h2{
width: 50%;
}
#textblock{
transform: rotate(-90deg);
width: 700%;
margin-left: -350%;
text-align: center;
font-size: 10px;
font-weight: bold;
}
#div01{background-color: red;}
#div02{background-color: gold;}
#div03{background-color: lightgreen;}
#div04{background-color: royalblue;}
#div05{background-color: pink;}
#div01,#div02,#div03,#div04,#div05{
width: 80%;
float: left;
display: none;
padding-left: 1%;
height: 300px;
overflow-x: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div id="blockpop" onclick="Exibir1()" ondblclick="Ocultar1()">
<div id="textblock">BLOCO 1</div>
</div>
<div id="div01">
<h2>BLOCO 1</h2>
<b>conteúdo</b><br>
</div>
<div id="blockpop" onclick="Exibir2()" ondblclick="Ocultar2()">
<div id="textblock">BLOCO 2</div>
</div>
<div id="div02">
<h2>BLOCO 2</h2>
<b>conteúdo</b>
</div>
<div id="blockpop" onclick="Exibir3()" ondblclick="Ocultar3()">
<div id="textblock">BLOCO 3</div>
</div>
<div id="div03">
<h2>BLOCO 3</h2>
<b>conteúdo</b>
</div>
<div id="blockpop" onclick="Exibir4()" ondblclick="Ocultar4()">
<div id="textblock">BLOCO 4</div>
</div>
<div id="div04">
<h2>BLOCO 4</h2>
<b>conteúdo</b>
</div>
<div id="blockpop" onclick="Exibir5()" ondblclick="Ocultar5()">
<div id="textblock">BLOCO 5</div>
</div>
<div id="div05">
<h2>BLOCO 5</h2>
<b>conteúdo</b>
</div>
In this way, what would be the most practical way to create a script that when you open a block, close all others that are open on the page? Is it possible to create a function within the
onclick
attribute in a tag that recognizes only two clicks to open and close any block?