-1

I'm using an image texture for a background (which is a repeated image), and I'm also using a sprite sheet. All of these are loaded via CSS.

I've tried using $(window).load() to fade in the images after load, but you can still see it rendering/loading.

I'm starting to think that $(window).load() only works for images in the DOM.

Is there a way to detect that a CSS image is loaded?

Vongdarakia
  • 379
  • 1
  • 12
  • 25

1 Answers1

0

You can use preloader to hide all content on your page until all elements will load.

HTML

 <div id="preloader">
        <div id="status"></div>
    </div>



<script type="text/javascript">
    //<![CDATA[
        $(window).load(function() {
            $('#status').fadeOut();
            $('#preloader').delay(350).fadeOut('slow');
            $('body').delay(350).css({'overflow':'visible'});
        })
    //]]>
</script> 

CSS:

#preloader {
    position: fixed;
    top:0;
    left:0;
    right:0;
    bottom:0;
    background-color:#aed0de; /* change if the mask should have another color then white */
    z-index:7; /* makes sure it stays on top */
}

#status {
    width:400px;
    height:418px;
    position:absolute;
    left:50%; /* centers the loading animation horizontally one the screen */
    top:50%; /* centers the loading animation vertically one the screen */
    background-image:url(../images/status.gif); /* path to your loading animation */
    background-repeat:no-repeat;
    background-position:top;
    margin:-209px 0 0 -200px; /* is width and height divided by two */
    text-align:center;
    text-transform:uppercase;
    font-size:1.6em;
    font-weight:bold;
    letter-spacing:0.1em;
    color:#3d6a7c;
    text-shadow: 4px 4px 2px rgba(150, 150, 150, 0.3);