Skip to content
Preload images and callback when they are all ready
JavaScript
Find file
Latest commit 697a8d5 @bahamas10 Update preloadimages.js
Failed to load latest commit information.
Makefile initial commit
README.md Update README.md
preloadimages.js Update preloadimages.js
preloadimages.min.js adding minified source

README.md

preloadimages.js

Preload images and callback when they are all ready

Usage

<script src="preloadimages.min.js"></script>
<!-- // defines preloadimages() -->

You can call it with an array or object of images

preloadimages(['1.png', '2.png'], function(images) {
  console.log(images);
  // => [img, img]
});

or

preloadimages({moon: 'moon.png', sun: 'sun.png'], function(images) {
  console.log(images);
  // => {moon: img, sun: img}
});

The function will callback when all of the images are loaded (or have failed to load). The argument passed to the callback is either an array or object to match the input, and if it is an array, it will be in the same order as the input array.

The items in the returned argument are new Image() elements.

License

MIT License

Something went wrong with that request. Please try again.