The pre-loader is hidden behind the block content and navigation bar

I've encountered an issue with my preloader where it's loading in front of the <body> element but not in front of the site's <navbar> or the {% block content %}. The CSS snippet to increase the z-index of the preloader is as follows: #preloader{z-index:999;}

  • Django 2.2.7
  • Bootstrap 4.4.1
  • JQuery 3.4.1

$(window).on('load', function() {
  $('#preloader').addClass('loaded');
  setTimeout(function(){
    $('#preloader').addClass("notta");
}, 2000);
});
#preloader:before {
  content: '';
  z-index: 999;
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,1);
}
#preloader.loaded {
  opacity: 0;
  transition: .3s ease-in 1s;
}
#preloader.notta {
    display: none;
}
<header>
<div class="flex-center" id="preloader">
    <div class="preloader-wrapper active">
        <div class="spinner-grow text-warning" role="status">
            <span class="sr-only">Loading...</span>
        </div>
    </div>
</div>
</header>

If I move the preloader to the bottom of the <body>, it loads on top of the {% block content %} but still remains underneath the navbar. Could this be related to the order of loading elements?

How can I ensure that the preloader displays above all other elements on the site?

Answer №1

Issue arises from the :before element in your css code. To resolve this, simply integrate it with #preloader:

  $(window).on('load', function() {
    $('#preloader').addClass('loaded');
    setTimeout(function() {
      $('#preloader').addClass("notta");
    }, 2000);
  });
#preloader {
  color: white;
  z-index: 999;
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 1);
}

#preloader.loaded {
  opacity: 0;
  transition: .3s ease-in 1s;
}

#preloader.notta {
  display: none;
}
<script
  src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous"></script>
  
<header>
  <div class="flex-center" id="preloader">
    <div class="preloader-wrapper active">
      <div class="spinner-grow text-warning" role="status">
        <span class="sr-only">Loading...</span>
      </div>
    </div>
  </div>
</header>

Answer №2

Here's a way to implement this functionality using only pure Javascript

`let preloader = document.getElementById('preloader');
window.addEventListener('load',function(){
preloader.style.display = 'none';
});`

Give it a try!

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

How to apply new CSS styles to override the existing ones for an element

I have a website with custom CSS styling applied to an <A> tag, including styles for A:hover. However, I need to remove these hover effects for one specific instance of the tag. Is there a way in CSS to set a property so that it does not change? Let ...

Using the reverse function to pass parameters when redirecting with HttpResponseRedirect

I have the following code snippet: return HttpResponseRedirect(reverse("named_foo"), request) How can I pass a parameter to the named_foo definition using the reverse function? The parameters of the named_foo definition are as follows: def fooMethod(r ...

Concerns with the dimensions of HTML thumbnails

view image description here I seem to be having an issue with the size of thumbnails on my website. The problem arises when a thumbnail with a long title is displayed, as it ends up taking up more space and affecting the layout. Is there a solution to ens ...

deleting hyperlink on mobile device

I'm trying to hide a specific div when the screen size is mobile, and currently I have: HTML <div id='top-btn'> <a class="fade-in" href="...">Top</a> </div> CSS #top-btn a { visibility: visible; opacity: 1 ...

"Troubleshooting a case where mongoDB's updateOne function is

I am in the process of removing certain references to objects within different sections (section1, section2, section3, others) in each file. Sample Document: { "_id": "64a3268474aa29e72b40c521", "name": "Test", ...

Issue with ng-repeat causing HTML table data to not appear

Trying to create a Flask web app, I encountered an issue while attempting to display tabular data on my webpage using AngularJS. Despite using ng-repeat to iterate through the data, it doesn't seem to work and no errors appear in the console. Can anyo ...

Next.js in combination with Tailwind CSS

While attempting to customize the styling for my Next.js 13 app, I encountered an error message that states: Syntax error: C:\Users\User\Documents\webdev\TicketingApp\ticketing-app\app\globals.css The text-default- ...

Creating a custom request for the Upload component in Ant Design Vue requires a specific set of steps and

I attempted to implement the solution provided in How should customRequest be set in the Ant Design Upload component to work with an XMLHttpRequest? but it doesn't seem to be working for me in Ant Design Vue. Could someone provide an example, please? ...

Utilizing jQuery AJAX with a plethora of dynamically created div elements

Within my JSP file, I have a series of divs that are created dynamically based on a database value. These divs have ids such as event1, event2, and so on. Let's focus on the div with the id event1. Inside this div, there is a button with the id foll1 ...

How can you generate a distinct id value for each element within an ngFor iteration in Angular 4?

I encountered an issue where I must assign a distinct id value to each data row within my *ngFor loop in angular 4. Here is the code snippet: <div *ngFor="let row of myDataList"> <div id="thisNeedsToBeUnique">{{ row.myValue }}</div> & ...

Creating a HMAC-SHA-256 signature in JavaScript for datatrans: A step-by-step guide

I'm currently working on an Angular project that involves implementing the Datatrans payment system. Unfortunately, I have been facing difficulties in generating a sign for the payment. I have been following the process outlined in this link (enter l ...

What is the most effective way to transfer data from a child component to a parent component when the child component contains multiple input fields?

Passing data from a parent component to a child component is something I need help with. Let's say I have a parent component with the following data: Parent component <template> <NameUser :data="userData"></Name ...

Enhance the performance of your React/NextJS app by controlling the rendering of a component and focusing on updating

I'm facing an issue with my NextJS application that showcases a list of audio tracks using an <AudioTrackEntry> component. This component receives props like the Track Title and a Link to the audio file from an external data source. Within the ...

Retrieving visual information from Google Street View entity

Looking for a solution to extract imagery from the Google Street View panorama within a web page? In my program, I navigate specific routes using Google Street View's javascript API controlled by an embedded Java applet on the same page. I am seeking ...

What is the best way to anticipate a return phone call?

Looking to retrieve the largest date from a folder by reading its contents. https://i.stack.imgur.com/KYren.png Here is the code snippet to read the folder, extract filenames, and determine the largest date (excluding today): async function getLastDate ...

Ways to send information to browser javascript from Spring MVC controller

Looking for the most efficient method to transfer data from Spring MVC to JavaScript. Let's say there is an array in JavaScript: var myArray = new Array(); And in the Java backend, there is another array: int[] myArray = new int[100]; What would ...

Creating InMemoryUploadedFile objects correctly in Django involves following specific steps to ensure the file is

In my Django project, I have implemented a Python function that resizes user uploaded images. The function utilizes the BytesIO() and InMemoryUploadedFile() classes to convert a PIL object to a Django UplodedFile before saving it in the model. Here is how ...

Unraveling HTML elements within a string using MongoDB: A step-by-step guide

Currently, I am in the process of creating a blog from scratch as a way to enhance my skills. The posts' content is stored as a long string in MongoDB with some random HTML tags added for testing purposes. I am curious about the conventional method fo ...

Exploring immersive virtual reality websites with a complete full-screen 3D experience

As I work on building a virtual reality website, I find myself pondering a challenging question: how can we seamlessly transition users from experiencing one VR website in full screen stereoscopic view to another, all without disrupting their immersive e ...

How come certain rectangles vanish when one rectangle completely fills the space?

Currently, I am encountering an issue with CSS paint worklet and I am trying to determine if it's a browser bug or an error on my end. In the worklet, I am drawing multiple rectangles. Strangely, when one rectangle covers the entire area, the others s ...