Last active
December 11, 2015 21:28
-
-
Save kazu69/4662610 to your computer and use it in GitHub Desktop.
jQuery image preloader
This file contains hidden or 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
images = [ | |
image1.jpg, | |
image2.jpg, | |
image3.jpg, | |
image4.jpg | |
] | |
preload: (images, callback) -> | |
count = images.length | |
# no image | |
if count == 0 | |
callback() | |
return | |
loaded = 0 | |
error = false | |
load = (url) -> | |
$('<img>').attr('src', url).load( (response) -> | |
loaded++ if $(@).get(0) | |
callback() if count == loaded | |
).error( -> | |
# somethig error events | |
) | |
load url for url in images | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment