Show a loading animation at the center of the page's visible area

Is there a way to add a loading animation on the visible part of a page with a container that has a vertical scroll? I've tried using a div with class:

.loading-animation {
    height:100vh;
    background: url(img/loading.gif) 50% 50% / 100px 100px fixed no-repeat;
}

However, the animation appeared at the bottom of the page instead of above the container. Then, I attempted:

.loading-animation {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    background: url('img/loading.gif') 50% 50% / 100px 100px no-repeat;
}

This solution placed the animation above the container but in the middle of the entire page rather than the visible area. Any suggestions on how to make this work would be greatly appreciated.

Edit1, Using Javascript:

var loading_animation;

function showLoadingAnimationModal() {
    loading_animation = document.createElement("div");
    loading_animation.style.cursor = "progress";
    loading_animation.className = "loading-animation";

    document.body.appendChild(loading_animation);
}

function hideLoadingAnimationModal() {
    if (loading_animation.parentNode == document.body) {
        document.body.removeChild(loading_animation);
    }
}

Here is an HTML template (using emberjs):

<script type="text/x-handlebars">
      <div align="center">
        {{outlet}}

        {{#if errorMessage}}
            <div class="alert alert-danger" role="alert">
                {{errorMessage}}
            </div>
        {{/if}}
      </div>
</script>

<script type="text/x-handlebars" data-template-name="login">
    <div class="container">
    <!--skipped elements-->
    </div>
</script>

Answer №1

Check out this JSFiddle

Cascading Style Sheets (CSS)

.maindiv{
 position: relative;
}
.loader
{
  position:absolute;
   top: 0;
   left: 0;
   width: 100%;
   height: 100%;
   z-index: 10;
   background: rgba(0,0,0,0.5);
}
.loader span
{
  height:30px;
  width:100px;
  padding:10px;
  margin:auto;
  top:0px;
  right:0px;
  left:0px;
  bottom:0px;
  position:absolute;
  background:#ddd;

}
.scrolldiv
{
  height:200px;
  overflow:auto;

}

HyperText Markup Language (HTML)

    <div class="maindiv">
    <div class=loader>
          <span>Loading</span>
    </div>
    <div class="scrolldiv">
[dummy text for demonstration purposes]
    </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Analyzing JSON parsing efficiency

I am currently working on a client application using jquery and html5 For my project, I have a data file that is 70 MB in size The file named data.json contains the following: var myData = [ { "id":"000000001", "title":"title1", "c ...

Bootswatch alternative for Bootstrap CSS without utilizing Google Fonts

Currently, I am in the process of developing a webpage and utilizing Bootswatch for styling. However, there are times when I need to work offline and host locally. The issue I am facing is that Bootswatch cannot be used offline due to the fact that it util ...

Designing the KendoUI combo box with a touch of style

Is there a way to customize the style of required and invalid fields for KendoUI elements, such as changing the background color of a required input field? I have been using the following styles: .k-textbox>input[required], .k-picker-wrap .k-input[re ...

Attempting to extract only the text content from a specific div using XPath

I am currently facing a challenge in writing a script to extract the title element from a poorly coded webpage. The developer who created this website did not use any classes, only div elements. Below is a snippet of the source code I am trying to scrape: ...

unusual occurrences with CSS and JavaScript when hovering over TEXTAREA or A elements

Lately, I've been facing an unusual issue in my web application (php) that was fine just a month ago. Upon hovering over a specific < TEXTAREA > or two buttons (add, exit) within a DIV, the background color of the DIV fills up, rendering the IN ...

Tips on personalizing the DateTimePicker component from Material-UI

I am currently working on customizing the DateTimePicker component provided by Material-UI. To access its documentation, please visit: One challenge I have encountered is the lack of styling information in the documentation. My goal is to change the main ...

The column on the right does not extend all the way to the bottom of the page

Hello, I currently have a website with the following design: I'm looking to extend the right column all the way down to the bottom of the body, even if there's not enough content to push it down. How can I accomplish this using CSS? Here is the ...

Injecting AngularJS directives and styling elements into the body section of a Twig template using the {% block body %} tag

I'm currently in the process of constructing a Rest API using Symfony 3 and Fosresbundle, with AngularJS responsible for fetching JSON data within twig templates. However, I've encountered an issue where I need to specify angularJS directives an ...

Is there a way to modify a button's aspect ratio when it is clicked?

Currently, I am utilizing the MUI v5 AppBar to craft a navigation bar with Tabs. My aim is to have the background of the Tab blend seamlessly with the main page background upon being clicked, as illustrated here: https://i.sstatic.net/e4bDn.png However, a ...

I cannot seem to alter the background color of my image through the use of external CSS

body { background-color: #f6f7d4; } h1, h3, hr { color: #68b8ab; } hr { width: 100px; border-style: dotted none none; border-color: gray; border-width: 5px; } img { background-color: black; } Although the external CSS code a ...

After the automation is finished, I am interested in outputting the IMDB rating of a movie or series to the terminal

I prefer using Google search to find the element because I find it easier to navigate compared to IMDB. import selenium.webdriver as webdriver print("This script is designed to retrieve the IMDb rating of a movie or TV series!!!") def get_results(search_ ...

methods for extracting header information using JavaScript

Is there a way to retrieve values from the header URL using JavaScript? Consider this scenario: www.example.com/content.html?param=value How can one extract this information upon redirecting to the page content.html? What techniques could be employed f ...

Leveraging keyboard input for authentication in Angular

Would it be possible to modify a button so that instead of just clicking on it, users could also enter a secret passphrase on the keyboard to navigate to the next page in Angular? For example, typing "nextpage" would take them to the next page. If you&apo ...

Is there a way to modify the CSS display property upon clicking a link or button?

I have a ul with the id of "menu-list". The display property is set to "none" in my CSS file, but I want it to switch to "flex" when a link is clicked. I am trying to use the click event on the link to change the display prop ...

Radio button fails to be marked as selected

Currently, I am conducting a test on , and one of the tasks involves styling Radio Buttons using JavaScript (jQuery). Despite my repeated attempts to reconstruct the code, I always encounter the same issue: although JS successfully sets the input radio but ...

Is there a way to horizontally center a content container in Flutter similar to a "max-width" container in CSS?

How can I create a centered content box like this in Flutter?: .content-box { margin-left: auto; margin-right: auto; width: 100%; max-width: 600px; background-color: blue; height: 100vh; } <div class="content-box"> Cont ...

Tips for concentrating on the initial input field produced by an ng-repeat in AngularJS

Currently, I am dynamically generating input fields using ng-repeat and everything is working smoothly. However, my requirement is to set focus on the first input that is generated by this ng-repeat based on their sequenceId values. So far, I have attempte ...

Displaying a value in a React component using material-ui's TextField

Can anyone help me with printing the email a user enters into the textfield within the Dialog when a button is clicked? I have been struggling to achieve this due to my function's structure. Any guidance would be greatly appreciated. export default fu ...

Error: Bootstrap/CSS not functioning properly on IE and ED browsers

Currently, I am tackling a web application project, and much to my surprise, I discovered that the CSS/bootstrap is not functioning properly on Internet Explorer and Microsoft Edge. Despite attempting various solutions found on Stack Overflow, none seem to ...

Unable to decrease the height of the textbox

Need help adjusting the height of a bootstrap textbox. <div class="form-group row"> <label class="col-xl-3">Posted Speed Limit (mph)</label><input type="text" class="col-xl-1 ps" autocomplete="off" id="sl" onkeydown="return key ...