0

I have a page that takes information from a database. It exports a lot of information, so it takes a few seconds to load. I do have an animation, but it is not behaving how I want it to behave. When a user clicks on a link, I want there to be a loading animation instantly, and it shows until the data on the page actually loads.

Here is what it actually does: When I click on a link, I wait 5 seconds, then the page loads with the animation, then the data loads. The problem is that I want the animation to run instantly, not wait 5 seconds, then run for half a second, then the data loads.

Here is my current JQuery code:

$(document).ready(function() {
  $("#content").hide();
  $(window).load(function() {
    $("#content").show();
    $("#content-loading").hide();
  })
})

content is the content that takes a while to load and content-loading has the loading animation.

0

3 Answers 3

3

$(document).ready() will only run when the DOM is done downloading, basically when </html> is downloaded at the end of your page. If your database data is part of the page, it will be loaded by the time the DOM ready event fires. Meanwhile, $(window).load() will fire when all the resources on the page have loaded; all the images, external stylesheets, etc.

Perhaps you could have a stylesheet before the data which hides the content, then an internal stylesheet at the bottom of your page, after the data, which makes the content display and the #content-loading element hidden?

Otherwise, you could load the data asynchronously in some way, with AJAX or in a frame.

Sign up to request clarification or add additional context in comments.

Comments

1

http://fgnass.github.io/spin.js/

See this, if you want to add a loading.....

Comments

0

your animation won't run until the whole page is loaded (including all that db stuff). Instead, load a page that has just your animation, and an AJAX call to the db data. Then the db call is asynchronous.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.