Last active
August 29, 2015 14:07
-
-
Save rbk/ce4411e742c2aa2cca0e to your computer and use it in GitHub Desktop.
Pre load images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Page this function a javascript array of image urls to preload them! | |
function pre_load_images(images){ | |
for( var i=0; i < images.length; i++ ){ | |
var img_new = document.createElement('img'); | |
img_new.setAttribute( 'src', images[i] ); | |
img_new.setAttribute( 'style', 'display:none;' ); | |
document.body.appendChild(img_new) | |
} | |
} | |
/* Example */ | |
// Array of image urls | |
var images = [ | |
'http://domain.com/images/image1.png', | |
'http://domain.com/images/image2.png', | |
'http://domain.com/images/image3.png' | |
]; | |
// Call function on page load passing in array | |
pre_load_images( images ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment