I would like to place a “please wait, loading” spinning circle animation on my site. How should I accomplish this using jQuery?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could do this various different ways. It could be a subtle as a small status on the page saying “Loading…”, or as loud as an entire element graying out the page while the new data is loading. The approach I’m taking below will show you how to accomplish both methods.
The Setup
Let’s start by getting us a nice “loading” animation from http://ajaxload.info
I’ll be using
Let’s create an element that we can show/hide anytime we’re making an ajax request:
The CSS
Next let’s give it some flair:
And finally, the jQuery
Alright, on to the jQuery. This next part is actually really simple:
That’s it! We’re attaching some events to the body element anytime the
ajaxStartorajaxStopevents are fired. When an ajax event starts, we add the “loading” class to the body. and when events are done, we remove the “loading” class from the body.See it in action: http://jsfiddle.net/VpDUG/4952/