Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9130205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:55:08+00:00 2026-06-17T07:55:08+00:00

Working on an HTML5/CSS3 project that requires some mildly large (~100k) sprite maps to

  • 0

Working on an HTML5/CSS3 project that requires some mildly large (~100k) sprite maps to be loaded and placed onto a <canvas>. The placement is no problem, but I’m running into the problem of accidentally place the images before they’re loaded, because there’s no way to detect load completion of images requested via javascript.

What’s the best way to preload images and get a handle on the oncomplete event? Right now I’m detecting pageload with the standard $(document).ready(), but I can adapt the code to any event handler required. If there’s a plugin that handles it all, then brilliant.

I’m a little more particular about the preloading though – if possible I’d like everything to stay inside javascript. Looking for something more elegant than placing the images in a hidden div or dummy css.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:55:09+00:00Added an answer on June 17, 2026 at 7:55 am
    var img = new Image();
    img.onload = callbackFunction;
    img.src = 'http://source.of/image.png';
    

    If you use this a lot, just create a function for it:

    function preloadImage (src, callback) {
        var img = new Image();
        img.onload = callback;
        img.src = src;
        return img;
    }
    

    If you want to fire a callback when all the images have loaded, use a deferred object:

    function preloadImages (paths, callback) {
    
        var deferreds = [];
    
        $.each(paths, function (i, src) {
            var deferred = $.Deferred(),
                img = new Image();
    
            deferreds.push(deferred);
            img.onload = deferred.resolve;
            img.src = src;
        });
    
        $.when.apply($, deferreds).then(callback);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going to be working on some HTML5/CSS3 that will be included in an
I'm currently working on a JavaScript project that uses the HTML5 canvas as a
I'm working on a design that has some image based shadows (can't use CSS3
Hello all I am working in javascript and html5.I want to ask that how
I'm using the HTML5 elements and in a project i'm working on and the
I am working on a new graph for my site, using CSS3/HTML5 (canvas tag).
I'm working on a HTML5 / CSS 3.0 / MVC 3 project in Visual
I have a small project I am working on HTML5 canvas and I wanted
I am currently working on a project that similar to http://www.beoplay.com/Products/BeoplayA9#under-the-hood using Javascript, HTML5
I am currently working on NetBeans 7.0 it did not have HTML5 and CSS3

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.