Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function preloadHero(images, callback) {
- var l = images.length;
- function loadImage(counter) {
- var img = new Image();
- // image loaded? call the next one
- img.onload = function() {
- counter++;
- // we done?
- if (counter == l) {
- if (callback && typeof(callback) === 'function') {
- callback();
- } else {
- return;
- }
- } else {
- // keep going
- loadImage(counter);
- }
- };
- // set the new image src to the image url
- img.src = images[counter];
- }
- // call the first one
- loadImage(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement