Learn how to design a customized loading screen using CSS with Phonegap

Currently working in Android with Phonegap / Cordova, I am faced with the challenge of optimizing page loading time due to numerous DOM objects being created. To address this issue, I am attempting to implement a "Loading..." screen to prevent users from being greeted by a blank screen. However, my attempts at using CSS for this purpose have been unsuccessful thus far.

In an effort to create the loading animation, I have referred to the following script:

http://stackoverflow.com/questions/1964839/jquery-please-wait-loading-animation

Placing the provided code snippet at the bottom of my HTML page, I then incorporated the corresponding CSS rules into my stylesheet as follows:

.modal {
display:    none;
position:   fixed;
z-index:    1000;
top:        0;
left:       0;
height:     100%;
width:      100%;
background: rgba(255, 255, 255, .8) 
            url('../img/loader.gif') 
            50% 50% 
            no-repeat;
}

body.loading {
overflow: hidden;   
}

body.loading .modal {
display: block;
}

To trigger the loading state, I included the following code snippet at the beginning of my application's JavaScript file:

$("body").on({
ajaxStart: function() { 
    $(this).addClass("loading"); 
},
ajaxStop: function() { 
    $(this).removeClass("loading"); 
}    
});

Despite implementing the suggested approach, I continue to encounter issues where the desired CSS layer and GIF animation fail to render, leaving me with the standard black screen during DOM object population. This has prompted me to question the compatibility of this type of loading screen within the Phonegap framework.

If anyone could offer assistance or insights on this matter, it would be greatly appreciated. Thank you.

* Additionally, upon further examination, I discovered that the JQuery library version used in the reference example is 1.7.2, whereas I am utilizing the latest version 2.0.3. The discrepancy in library versions appears to impact the functionality of the example when tested in jsfiddle, leading me to suspect potential deprecations in the code.

Answer №1

My issue was successfully resolved on a different forum by a helpful user named jcesarmobile.

"

I found the solution on the jQuery website which stated that AJAX events should be attached to the document element.

Starting from jQuery 1.9, global AJAX events (ajaxStart, ajaxStop, ajaxSend, ajaxComplete, ajaxError, and ajaxSuccess) are now only triggered on the document element. This means that the code should be modified to listen for AJAX events on the document instead. For example, if your code currently looks like this:

$("#status").ajaxStart(function(){ $(this).text("Ajax started"); }); You should change it to this:

$(document).ajaxStart(function(){ $("#status").text("Ajax started"); });

"

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

Interaction between Javascript and PHP is only triggered upon the second click

Despite my efforts to find a solution, I've been facing some challenges... I'm currently developing a mobile hybrid app. The user is required to input their ID number, which is then sent to a javascript function for validation. Following this, a ...

What is the best way to use jQuery to fill a dropdown menu with options from a JSON object?

Looking to populate a dropdown box #dropdown with values from a json object stored in a JavaScript string variable. How can I access each element as value/label pairs and insert them into the dropdown? The structure of the json string is as follows: [{"n ...

Implementing RequireJS Singleton pattern with Web Workers

I'm currently working on a JavaScript project that utilizes the latest version of RequireJS. One of the modules I am defining is chessWorker, as shown below: var worker; define("chessWorker", ["jquery", "messageListener"], function($, listener) { ...

When a div element overlaps with other elements, everything below it continues to be displayed on top of

I have a DIV that is displaying correctly. However, content that is supposed to be below the DIV is showing on top of it. I need help fixing this issue. I have tried the solutions provided in other similar questions but none of them have resolved my proble ...

The Vue.createApp function seems to be malfunctioning, whereas using the new Vue() method is functioning correctly

When running my code, I encountered the following error message: tesyya.js:16 Uncaught TypeError: Vue.createApp is not a function. My code snippet looks like this: const app = Vue.createApp({ data() { return { count: 4 } } }) const vm ...

Extract SCSS import filepaths using NPM and Gulp

Currently, in my gulp setup, I have several CSS files being produced - a general 'core' one, and then template-specific stylesheets. Instead of re-compiling all stylesheets with each change, the setup only compiles the necessary ones. However, t ...

How can I implement the ternary operator in React Native and resolve my code issue?

Hello, I'm looking to implement the ternary operator in my code. Specifically, I want to render a FlatList if `cookup` has a value. However, if `cookup` is an empty array, I want to display some text instead. <FlatList data={cookUp} ...

Utilizing Ajax to retrieve an array of input textboxes and showcase the outcome within a div container

This is the form that I have designed for displaying information: <form name='foodlist' action='checkout' method='POST'> <table> <tr> <td>Product Name</td> <td>Price</t ...

Concealing numerous tables depending on the visibility conditions of subordinate tables

I have the following HTML code which includes multiple parent tables, each with a specific class assigned to it: <table class="customFormTable block"> Within these parent tables, there are child tables structured like this: <table id="elementTa ...

Encountering an error in React Native: Unable to access property 'length' as it is

Currently, I am working on developing a registration application and I have encountered some issues in the final phases when attempting to submit the new data to the server. Below is the script I am using: import React from 'react'; import React ...

How can I bind the ID property of a child component from a parent component in Angular 2 using @Input?

I have a unique requirement in my parent component where I need to generate a child component with a distinct ID, and then pass this ID into the child component. The purpose of passing the unique ID is for the child component to use it within its template. ...

An interactive selection tool for a website's navigation bar

Struggling to implement a dropdown menu for my navbar, none of the CSS methods I've tried seem to work. My current HTML code is as follows... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-t ...

Encountering an issue with NextJS useRouter when it is utilized within a function

I have encountered a puzzling issue that I can't seem to resolve. In my experimentation with NextJS, I am attempting to access the params in the router by utilizing the useRouter hook and integrating it with the querystring plugin to parse the asPath, ...

Transmit and receive information between Javascript and Node.js through Express framework

Currently, I am utilizing the Express platform along with the Twilio Node.js SMS API and JavaScript to send text messages to my users. However, I am facing an issue in sending data through GET variables on the front-end and capturing those values with node ...

Magnify novice mistakes: Unhandled promise rejection and Ensure every child has a distinct "key" property

Currently, I am working through Amazon's Getting Started with AWS tutorial found here: https://aws.amazon.com/getting-started/hands-on/build-react-app-amplify-graphql/module-four/ After successfully building and hosting the app on git, I noticed that ...

Tips for enhancing a table with extra functionality in Angular 6

Hi there! I've created a table using Angular 6 and now I'm looking to enhance it with some extra functionality: Implement an overall table search feature Allow users to sort the table by columns Add a "Page x of n" option for pagination I woul ...

Alternate Row Colors Using Odd/Even CSS Styling for Main Headings

In my expand/collapse table, I have set up alternating row colors (dark grey and light grey) that adjust automatically when expanding or collapsing. The challenge I'm facing is that for certain rows, I want to apply a specific background color using ...

Unexpected behavior in the AngularJS UI Bootstrap datepicker causing dates to shift

Hi there, I have encountered an issue with setting the default date format (YYYY-MM-DD) in the UI Bootstrap datepicker input field using momentjs. Everything seems to display correctly until I try to console log the selected date. It appears that an additi ...

Can you explain the difference between serif and sans-serif fonts?

Can you explain the distinction between serif and sans-serif when it comes to the CSS font-family attribute? ...

Concluding the dialogue once the post request has been successfully processed

My tech stack includes React, Redux, NodeJS, and ExpressJS. For the front-end, I'm utilizing material-ui. Within my application, I have implemented a dialog that allows users to input information and sign up. Upon clicking submit, a POST request is in ...