SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist anjanesh's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onload for background-image

    <img> has an onload event that I can call when the image has fully loaded.
    Is there any event that fires when a css background-image has loaded ?
    Anjanesh

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Anjanesh,

    there isn't, if you need to detect when a background-image has loaded, use Image preloading:

    Code JavaScript:
            function OnImageLoaded (img) {
    			alert ("The image has been loaded: " + img.src);
    		}
     
            function PreloadImage (src) {
                var img = new Image ();
    			img.onload = function () {OnImageLoaded (this)};
                img.src = src;
            }
     
    		PreloadImage ("image1.png");
    		PreloadImage ("image2.png");

    If you need further details, the following links will be useful:
    Load, unload and state events,
    onload event,
    Image object.
    Gumape


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •