Javascript - loading/busy indicator or transparent div over page on event click

后端 未结 5 2063
萌比男神i
萌比男神i 2020-12-09 06:45

i got a client side javascript function which is triggered on a button click (basically, its a calculator!!). Sometimes, due to enormous data on the page, the javascript cal

5条回答
  •  一向
    一向 (楼主)
    2020-12-09 06:51

    For the loading message, I would use a

    with position:absolute, position it using left and top, and set the display to none.

    When you want to show the loading indicator, you're going to have to use a timeout otherwise the div won't display until your processing is done. So, you should modify your code to this:

    function showLoadingIndicator()
    {
        // Display div by setting display to 'inline'
       setTimeout(CalculateAmountOnClick,0);
    }
    
    function CalculateAmountOnClick()
    {
      // MY time consuming loop!
        {
        }
      // Remove transparent div 
    }
    

    Because you set the timeout, the page will redraw before the time-consuming loop happens.

提交回复
热议问题