Scroll bar showing alone

Asked

Viewed 328 times

1

Follows code:

HTML:

<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<div id="myModal" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body" style="height: 300px">
        <div class="loader" style="position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto;"></div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
    <!-- /.modal-content -->
  </div>
  <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

CSS:

.modal-body {
  max-height: calc(100vh - 210px);
  overflow-y: auto;
}

.loader {
  border: 16px solid #f3f3f3;
  /* Light grey */
  border-top: 16px solid #3498db;
  /* Blue */
  border-radius: 50%;
  width: 120px;
  height: 120px;
  animation: spin 2s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

If you prefer Jsfiddle: https://jsfiddle.net/ZcLSE/1801/

Problem:

It is showing the scroll bar alone while loading makes animation. How can I fix this ?

  • it is necessary to scrollbar ?

  • Yes, after loading, it will load the contents ...

  • And where is the function of loading ? Put here on the question, do not need to use external websites, just paste the code select it and press CTRL+K to format.

  • I don’t call the function loading, itself is in html. After returning the ajax function, I do it myself hide to hide animation loading. It seems that the problem is in css.

  • @Souza Post edited, see !

1 answer

3


You can hide the overflow-y as long as it is loading is being displayed when hiding the loading define the overflow-y as auto again.

$('#myModal .modal-body').on('scroll', function() {
    console.log('scroll y');
});
// oculta o overflow-y
$('#myModal .modal-body').css({
  	'overflow-y': 'hidden'
  });
/// Apenas para simular
setTimeout(function(){
  $(".loader").hide(); // Oculta o loading
  $('#myModal .modal-body').html('<p>Paragrafo</p><p>Paragrafo</p><p>Paragrafo</p><p>Paragrafo</p><p>Paragrafo</p><p>Paragrafo</p><p>Paragrafo</p>');
  // Define o overflow-y como auto
  $('#myModal .modal-body').css({
  	'overflow-y': 'auto'
  })
}, 5000);
.modal-body {
  max-height: calc(100vh - 210px);
  overflow-y: auto;
}

.loader {
  border: 16px solid #f3f3f3;
  /* Light grey */
  border-top: 16px solid #3498db;
  /* Blue */
  border-radius: 50%;
  width: 120px;
  height: 120px;
  animation: spin 2s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<div id="myModal" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body" style="height: 300px">
        <div class="loader" style="position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto;"></div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
    <!-- /.modal-content -->
  </div>
  <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

Browser other questions tagged

You are not signed in. Login or sign up in order to post.