Advertisement
Guest User

Untitled

a guest
May 25th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. function preloadHero(images, callback) {
  2. var l = images.length;
  3. function loadImage(counter) {
  4. var img = new Image();
  5. // image loaded? call the next one
  6. img.onload = function() {
  7. counter++;
  8. // we done?
  9. if (counter == l) {
  10. if (callback && typeof(callback) === 'function') {
  11. callback();
  12. } else {
  13. return;
  14. }
  15. } else {
  16. // keep going
  17. loadImage(counter);
  18. }
  19. };
  20. // set the new image src to the image url
  21. img.src = images[counter];
  22. }
  23. // call the first one
  24. loadImage(0);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement