0

I have a CSS animation with sound, however, when the page initially loads, the sound is delayed. I would like a way to wait until everything on the page has loaded before I load the page. How can I do this? I found one script here: http://css-tricks.com/snippets/jquery/display-loading-graphic-until-page-fully-loaded/ but I was wondering if there was something even simpler.

1
  • I noticed the page you linked uses jQuery, but it's not specified above in the tags. Are you looking for a pure JavaScript solution? Also, please post any relevant code of your own in your post so we can see what you've tried.
    – Chase
    Jan 31, 2013 at 15:01

1 Answer 1

3

The link you provided is the simplest and best way to do this. No need to look for anything else.

<script>
    // Wait for window load
    $(window).load(function() {
        // Animate loader off screen
        $("#loader").animate({
            top: -200
        }, 1500);
    });
</script>   
3
  • 5
    I don't see jQuery tagged in this question, so I guess you should also recommend window.onload = function () { // code } ;
    – Ian
    Jan 31, 2013 at 15:33
  • 1
    What is the benefit of window.onload = function () { // code } ; ? Would it be beneficial to have both that code and the previous code?
    – JVE999
    Jan 31, 2013 at 18:05
  • 1
    The code I posted is just jQuery's way of doing ` window.onload = function () { // code }` so it would be redundant.
    – John Conde
    Jan 31, 2013 at 18:07

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.