Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html preloader - delay page load

I need some help with my new template :). Before the webpage loads I want to show a preloader gif. I done it, however it shows just a little, because the page loads very fast. So I would like to delay the page (with 2 seconds, as an exemple), without affecting the preloader, so it (the preloader) would appear for 2 seconds, so until the page loads.

Here is my code (note that it will not work on jsfiddle, because I can't upload the .gif file): jsfiddle.net/hLmxpsnw/

like image 452
Lawwwwwee Avatar asked Aug 09 '14 14:08

Lawwwwwee


People also ask

How do I add a delay on page load?

In order to delay the page load time simply add ? loading=1 to the end of the URL, this will cause the page to add a loading dialog and refresh the page 3 seconds later.

How do you delay a page in HTML?

Use the setTimeout() function in JavaScript to load a webpage after some interval. This function waits for some seconds and then loads the web page.

How do you show page loading Div until the page has finished loading?

Step 1: Add a background with a spinner gif on top of the page, then remove them when everything is loaded. Step 2: Add a little script right after the opening body tag to start displaying the load/splash screen.


1 Answers

For whatever reason u want it its done using setTimeout here is the code

jQuery(document).ready(function ($) {
    $(window).load(function () {
        setTimeout(function(){
            $('#preloader').fadeOut('slow', function () {
            });
        },2000); // set the time here
    });  
});

jsfiddle http://jsfiddle.net/harshdand/593Lqqnm/2/

like image 144
Harsh Avatar answered Sep 29 '22 11:09

Harsh