How to set a loading time of the website

Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
Posts: 107

How to set a loading time of the website

I've a website loader in GIF format but it doesn't appear because the page is loaded in 0.01 seconds.
Is there possible to set a loading time to 2 seconds to display the loader animation?

Here is an example of a preloader with jQuery using the delay() method (2 sec = 2000), wrapped inside the 'load' event.

Code: Select all

.loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  background-color: white;
  display: flex;
  justify-content: center;
  align-items: center;

<div class='loading'>
  <img src='your_image.gif'>

<div>Content of the page.</div>

$(window).on('load', function() {

Similar Topics