Как сделать div занимает 100% ширины, когда другой div скрывается - PullRequest
0 голосов
/ 27 апреля 2020

Идея состоит в том, что один div занимает 100% экрана <<strong> map > когда второй скрыт <<strong> chart >. Также я хотел бы знать, почему, когда я нажимаю на тег ввода, он выполняет функцию и не ждет нажатия кнопки.

function hidechart() {
  var x = document.getElementById("chart");
  if (x.style.display === "none") {
    x.style.display = "block";
  } 
  else {
    x.style.display = "none";
  }
};
* { padding: 0; margin: 0; }
html, body, #fullheight {
  min-height: 100% !important;
  height: 100%;
}
.leaflet-container { 
  position: fixed;
  width:  50%;
  height: 100%;
}
#chart{
  position:absolute;
  width: 50%; 
  height: 50px;
  top:2%;
  right:0;
}
<div id="map" ></div>
<div class="btn-group" style="position:fixed">
  <button onclick="hidechart()" >Graficas</button>
  <button type="button" id="alldep" class="btn" >Todos</button> 
</div>

<form id="form" onsubmit="return false;">
  <input style="position:fixed; top:0%; left:14%; width:10%;" type="text" onfocus="this.value=''" id="userInput" />
  <button style="position:fixed; top:0%; left:5%; width:8%;",stype="button" onclick="query();">Consultar</button>
</form>

<div id="chart"  align="right">
  <div class="row">
    <div id="chart-area"></div>
  </div>
</div>

1 Ответ

0 голосов
/ 27 апреля 2020

Вам нужна эта кнопка?

var map = document.getElementById("map");
var chart = document.getElementById("chart");

function hideChart() {
  chart.classList.add("hide");
}

function query() {
  alert("query");
}
* { padding: 0; margin: 0; }
    html, body, #fullheight {
        min-height: 100% !important;
        height: 100%;
    }
.leaflet-container { 
    position: fixed;
    width: 100%;
    height: 100%;
    }
    
#map {
  position: absolute;
  z-index: 0;
  top: 0;
  bottom: 0;
  width: 100%;
}

#chart{
    position:absolute;
    text-align: center;
    height: 50%;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #efefef;
    right:0;
    width: 100%;
    z-index: 1;
    }
    
#chart.hide {
  opacity: 0;
  transition: opacity .5s ease-out;
}

.container {
  position: relative;
  width: 100%;
  height: 100%;
}
<div class="container">
  <div id="map" ></div>
   <div class="btn-group" style="position:fixed">
      <button onclick="hideChart()" >Graficas</button>
      <button type="button" id="alldep" class="btn" >Todos</button> 
  </div>

  <form id="form" onsubmit="return false;">
      <input type="text" onfocus="this.value=''" id="userInput" />
      <button type="button" onclick="query();">Consultar</button>
  </form>

  <div id="chart" align="right">
      <div class="row">
          <div id="chart-area">
            <h1>This is where the chart is</h1>
          </div>
      </div>
  </div>
</div>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...