Load high-quality gif picture in advance

My task involves a lengthy process that takes several seconds to complete.

To make the waiting time more bearable, I have implemented an animated loading page.

<style>
   .modal_gif {
      display:    none;
      position:   fixed;
      z-index:    1000;
      top:        0;
      left:       0;
         height:     100%;
         width:      100%;
         background: rgba( 255, 255, 255, .8 ) 
         url('static/loading.gif') 
         50% 50% 
         no-repeat;
         background-size: 80%, auto;
        }
    body.loading .modal_gif {
         overflow: hidden;   
         }
         body.loading .modal_gif {
         display: block;
         }
        
 </style>
<script>
       $(document).on({
          ajaxStart: function() { $body.addClass("loading");    },
          ajaxStop: function() { $body.removeClass("loading"); }    
    });
</script>

Unfortunately, the gif file is quite large at 1MB and does not load properly after the first request, leaving only a faint overlay on the screen.

All subsequent requests work fine, indicating a potential issue with the gif loading mechanism.

I am seeking a way to preload the animated gif file as hidden and ensure it displays even for the initial request. Any ideas on how to achieve this?

Answer №1

To preload an image, you can use a hidden dummy img tag instead of setting it to display none. Additionally, consider the following approach:

.modal_gif {
  visibility: hidden;
  display: block;
  pointer-events: none;
}

body.loading .modal_gif {
  visibility: visible;
  overflow: hidden;
}

You can also experiment with opacity levels, but the important thing is to include pointer-events: none; so that the image remains clickable through.

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

Fetching data using JSONRequest sample code

I am new to web development and this is my first attempt at using JSON. On the JSON website (http://www.json.org/JSONRequest.html), they recommend using JSONRequest.get for certain tasks. However, I keep running into an error stating "JSONRequest is not ...

Utilizing AJAX to interact with a securely authenticated ServiceStack service

In my recent project, I have been working on a modified version of the ServiceStack Hello World example that includes authentication. The main objective is to create a RESTful API with services that require authentication and are accessible through Ajax fr ...

jQuery click event not working post Ajax request returned a 403 error

I am facing an issue with my ajax request where I receive a 403 error message. Strangely, when this error occurs, the click() function associated with the ajax call stops working. There is no manipulation of HTML elements before or after the ajax call, and ...

Using the goBack function in React Router does not add the previous location to the stack

In React Router v4, I have a list page and a details page in my web application. I want to implement a 'Save and close' button on the details page that redirects the user back to the list page when clicked. However, I noticed that after the user ...

Having trouble fetching AJAX information from PHP

I'm currently developing a basic application that is designed to determine your current location, utilize AJAX to send the coordinates to a PHP file, and then compute distances in PHP to showcase nearby shops. Here is my JavaScript and AJAX code: $( ...

Guidance on modifying a sub row within a main row in Sails.js

I am currently working on a sails.js application This is the model structure for my application: name: String, address:String, appSettings: { header: String, color : String, font: String, } In my development process, I have utilized independ ...

WebSocket connection issues are being experienced by certain users

While using socket.io, I encountered an issue where some users were unable to send messages with the message "I can't send a message why?". After researching the problem, it seems that the firewall or antivirus software may be blocking websockets. If ...

How can I effectively enable the close button on the NbAlertComponent to dismiss an alert?

I have been utilizing the nebular framework in my project and I am struggling to figure out how to make the close button of the NbAlertComponent actually close the alert. When I say close, I mean stop displaying the alert after clicking on the close button ...

methods for obtaining specific rows from a master table and a child table within a JTable

Here I am attempting to write like this.. However, this code is not functioning as expected for me. I am receiving the alert message: [{rcid:1}] Nevertheless, I desire an alert message like this: [{rcid:1, rdsid:10}] Note: rcid represents the selected ...

Preserving the dimensions of an expandable div

Is there a way for a div to maintain its print layout while still allowing for zooming? I attempted to enable zoom functionality on a div using jQuery to adjust the height and width percentages of a specific div with the ID "page". <div style=" heigh ...

The concept of asynchronicity and callbacks in JavaScript

As a newcomer to the world of JavaScript and Stack Overflow, I have been learning about synchronous, asynchronous, and callbacks through various videos and blogs. However, I still have a lingering doubt. If synchronous code means following a sequential ord ...

The issue where all buttons in a list are displaying the same ID

I am facing an issue with a row of buttons, all having the same class add-btn. Whenever I click on one button, I intend to log the id of its containing span. However, currently, all buttons are logging the span id of the first add-btn in the list. $(&apos ...

Mongoose: Imposing Requirements on Optional Fields

I have a Mongoose Schema setup like this: const PostSchema = new mongoose.Schema({ title: { type: String, required: true, }, content: { type: String, required: true, }, ...

Retrieving the content of a component tag in Vue

Recently, I've been experimenting with Vue and I'm interested in achieving the following: <snippet name="Select From Table"> SELECT * FROM database.table </snippet> I want to create a link that, when clicked, triggers a ...

Encountering a ng-select2 Error with Angular version 4.1.3

I have recently installed the ng-select2 package, but I encountered an error when trying to compile my code using 'ng serve'. Node version: 8.10.0 NPM version: 6.0.0 Another list item Operating System: Windows 7 ERROR in d:/PATH-TO-PROJECT-F ...

Ways to showcase HTML content in angular when receiving entities

Is there a way to properly display HTML characters using HTML entities? Take this scenario for example: Let's say we have the following string: $scope.myString = "&lt;analysis mode=&quot;baseball&quot; ftype=&quot;&quot; version ...

Fade-in effect applied to images upon exposure

Is there a way to fade in an image based on the percentage scrolled, rather than a set number of pixels? I want my website to be responsive and adjust to all screen resolutions. Or perhaps is there a method to have the image fade in when it enters the fiel ...

Total the values of several items within the array

Here is the data I currently have: const arrayA = [{name:'a', amount: 10, serviceId: '23a', test:'SUCCESS'}, {name:'a', amount: 9, test:'FAIL'}, {name:'b', amount: ...

Visible background between div elements

There seems to be a background color visible between the image divs. I initially suspected it could be related to margins. Even after attempting to set the div to absolute positioning and the parent to relative, the problem persists. The picture still fail ...

Can error pages be customized dynamically for Exceptions in JSF/AJAX?

Is there a way to dynamically set an error page in JSF? I am looking to automatically refresh the page whenever a ViewExpiredException occurs. Currently, I am utilizing omnifaces FullAjaxExceptionHandler to handle my exceptions, but it relies on error page ...