Loading content, Please wait..

An easy way to create Loading Bar!

Posted under: HTML & CSS, Web Development, jQuery
33 Comments | 14515 Views | Share This

“People count up the faults of those who keep them waiting”
Seems like I kept them busy decoding this loading bar :D

How to create a loading bar

How to create a loading bar

Recently, while browsing I landed on a page on StackOverflow.com where people were discussing about how I implemented this loading bar on CSSJockey.com. I could sense a lot of confusion in the discussion so thought I would take the mystery out as I love to share best practices. Here’s how you can create a loading bar in few steps..

Things You’ll Need

  1. A nice loading image: If you are good in creating animated GIF images that’s nice, otherwise you can create a loading image with this cool Ajax Loading Gif Generator.
  2. jQuery: We are creating this loading bar using jQuery so download jQuery latest version here.

jQuery Code within <head>..</head> tags

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(window).load(function(){
      $("#loading").hide();
})
</script>

HTML Code within <body>..</body>tags

<div id="loading">
Loading content, please wait..
<img src="loading.gif" alt="loading.." />
</div>

Make sure you add this code just below the starting <body> tag so it should be downloaded first.

CSS Code for loading DIV

#loading {
    position:absolute;
    width:300px;
    top:0px;
    left:50%;
    margin-left:-150px;
    text-align:center;
    padding:7px 0 0 0;
    font:bold 11px Arial, Helvetica, sans-serif;
}

Use your imagination and create something nice & unique.

View Demo | Download Source Code

Your comment, suggestion and feedback is highly appreciated.

There’s more to come to stay tuned…

33 Responses to “An easy way to create Loading Bar!”

 


24 Aug, 2010

thnk for sharing….if u dont mind can u sharing loading code for ur page..

 


26 Aug, 2010

Sure, I’ll try to write a tutorial on this next week. Thanks!!

 


18 Aug, 2010

I see that you have updated your loading bar with a lightbox effect. I have tried combining them, but it didn’t work. Would you be able to update your tutorial for this?

 


18 Aug, 2010

Replied to your previous comment, try that code. I’ll try to write a tutorial for the same..

 


25 Jul, 2010

hi
I insert the codes. How can i preview it in my local pc, before upload it to server?
tnx

 


26 Jul, 2010

You need to install a local server on your computer to replicate similar environment on your local computer.
For PC you can download Wamp and if you are using Mac or Linux you can download XAMPP or MAMP.

 


20 Jul, 2010

Thank you so much…useful tip

 


25 Jun, 2010

great post.. nice and awesome. thank you…

 


02 Jun, 2010

Well nice tutorial but this only waits until the DOM is loaded i think, and it doesnt really check if all the images and stuff have loaded.

Oh, someone asked about a percentage loading bar: Well, you cant do a percentage loading bar for all loading things, especially for a webpage!

 


25 May, 2010

very nice tutorial. i wish a body which want get sure from it.

thanks

 


13 May, 2010

Really Nice thanks.

 


10 May, 2010

Excellent!!!

Thank you. I’ve already tested on my site and works perfect!!!!

 


26 Apr, 2010

Hello to all,

What I want to do, is create a loading thing [ i already have mine ready for use ] but to show it for say 5 seconds then it re-direct to another webpage .. is there a way to do this.. well.. I’m sure there is tbh, Please help, thanks !

 


19 May, 2010

You can use Javascript setTimeout() function to achieve this.

 


22 Jan, 2010

Hi, Mohit.
Another great tips after Santa’s says on dec.
I will try in myblog. Thanks

 


16 Jan, 2010

I see how this works for a page loading, but do you know how to do something like this if you are waiting for the content to be generated in php?

Thanks

 


18 Jan, 2010

@destry: If you are using ajax you can call the loading bar within your code. In jQuery you can use the following code:

$(“#loading”).ajaxStart(function(){
$(this).show();
});

 


12 Jan, 2010

Huh, i can’t see the preview image. Btw, nice work.

 


02 Jan, 2010

well i would like to know how to make my loading bar appear first and then once the page is done loading it should redirect the person .. any ideas ?? please email me at arjhun.s@gmail.com .. thanx people

 


11 Dec, 2009

Great tip, thank you.

 


23 Nov, 2009

Great work.. !!
Thanks for sharing.

 


03 Sep, 2009

Thanks for the tutorial, i will use that in my page. I wish it would also show the percantage…

 


09 Jul, 2009

This is wonderful! Thank you so much!

Quick question:

How would I call that top function if a form was submitted? I have a file upload section I am working on and could use a cool loading bar like this when the upload form is submitted…

 


09 Jul, 2009

You can use this function on $(“#formid”).submit() and use $.ajax(options) to accomplish this.
Here’s an example:

$.ajax({
type: “POST”,
url: “some.php”,
data: “name=John&location=Boston”,
success: function(msg){
alert( “Data Saved: ” + msg );
}
});

 


26 May, 2009

Thanks for the post. Relatively easy….it took me some time to get the jQuery to work.

 


30 Apr, 2009

Good post dude.

 


27 Apr, 2009

hi i have tried progress bar in my site.it works fine. but it not displays all the time. Moreover while displaying this image, it looks displaying in separate page. i want to display it in my current page when the page takes more time to load……

Any ideas…

 


27 Apr, 2009

Please share the link of your website where you’re trying to display the loading/progress bar, so that I can take a look and help you out with any issues.

 


04 Mar, 2009

Mohit Aneja,

That was very helpful Mohit!! I never thought that you’ll find my question in Stackoverflow!

I’ll definitely never forget your helpful spirit!

How did you know about the question in Stackoverflow? You are not even registered user yet!

 


04 Mar, 2009

I saw a link back in WordPress Dashboard and checked your entry on Stackoverflow.com. I love to share best practices so thought answering this question will be a good start.

You can join our Google Group and be a part of CJ community http://groups.google.com/group/cssjockey

 


04 Mar, 2009

Thanks for sharing – Nifty tip!

 


04 Mar, 2009

excellent tutorial.

 


04 Mar, 2009

Thanks for sharing, I will try this on my website…


 

Trackbacks

Leave a Reply


This field is required.



This field is required.




I want to thank you for developing my site as per my design and helping me meet my web requirements on time and as per my need. I am sure we can work together on more projects in the future.
~ Teddy Jacob | TeddyJacob.net

"Mohit did an excellent job on a web project for me. The look, design, and service were all great. I really appreciated his work and the time he took to explain things. I highly recommend Mohit." ~ Chris Barnstable-Brown
Top qualities: Great Results , Good Value , On Time

"After hiring Mohit for the first time in 2007... I kept on consulting, hiring, and using Mohit's expertise in many website development projects where he exhibited unique talent in delivering his work on time and on budget." ~ Ali Husain
Top qualities: Great Results , Expert , On Time

"CSSJOCKEY is AWESOME. His work was fast, extremely well executed and we will DEFINITELY use his services in the near future. Having someone like this in our team makes life a hell of a lot easier. We absolutely 110% recommend using his web services." ~ Dan Atkins, Creator of the Superhero Mindset Programme

"Mohit is the Man! He whipped up a custom design for his coming soon plugin within a day and nailed it. His plugin is so easy to install and set up. I couldn't be more happy! He responded to my inquiry very quickly and answered all my questions. I'll definitely use his services again in the near future." ~ Client (Rebecca Cunningham)

"CSSJockey designed a very clean and beautiful layout for us and then built an easy to manage website. The project was quick and painless, a pleasure for sure." ~ Client (NDA)

Awesome theme! Thanks much. I love this theme, especially granite and copper dust.. ~ Vivek

Accredits & Testimonials!