jQuery.inMemoryImageLoader = function(strURL, intMaxWaitMilliseconds, callbackFunction)

Loads an image in memory then returns the image (or null) via a callback function.

Example

$.inMemoryImageLoader("graphics/logo.png", 30000, function(loadedImage) {
	if (loadedImage) {
		// Now that the image has been loaded, you can assign it
		// as the source of an image element, size the element, etc.
	} else {
		// Perhaps there is a default image you can use if the
		// selected one didn't load.
	}
});

Parameters

  • strURL - The URL of the image to load.
  • intMaxWaitMilliseconds - The maximum number of milliseconds to wait before deciding that the image load has failed in case the error event is never raised.
  • callbackFunction - The function to call when the image finishes loading or fails to load. Must take a single argument that is the image  element (not a jquery element) or null if the load fails.

Notes

The code attempts to use the load and error events for an image. These sometimes do not fire, though. So, the backup plan is to poll for the image to see if it ever loads and to have the maximum wait time before deciding to give up.

Last edited Jul 10, 2012 at 3:03 AM by cmaterick, version 6

Comments

No comments yet.