Sunday, 24 March 2019

How to show loading message/image during function call in JavaScript?


HTML

<select class="options-selector" id="drpAbcOptions" onmousedown="$('#loader').show();" onmouseup="$('#loader').hide();" onchange="callSomeFunction()"></select>

<div id="loader" style="display:none;"></div>

CSS

#loader {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  width: 50px;
  height: 50px;
  margin: -75px 0 0 -75px;
  border: 8px solid #f3f3f3;
  border-radius: 50%;
  border-top: 8px solid #3498db;
  -webkit-animation: spin 2s linear infinite;
  animation: spin 2s linear infinite;
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }

}


Script

$(document).ready(function(){
     $('#loader').show();
});

$(window).on('load', function (){
  setTimeout(function (){
   try
   {
       loadData();
   }
   catch(ex){}
   finally
   {
       $(loader).hide();
    }
  }, 1000);
});

No comments:

Post a Comment