Skip to content

Instantly share code, notes, and snippets.

@juandinella
Last active January 11, 2018 00:35
Show Gist options
  • Save juandinella/1350615f03dc3a3d190ec72f7dc45104 to your computer and use it in GitHub Desktop.
Save juandinella/1350615f03dc3a3d190ec72f7dc45104 to your computer and use it in GitHub Desktop.
(function($) {
var imgList = [];
$.extend({
preload: function(imgArr, option) {
var setting = $.extend({
loaded_all: function(loaded, total) {}
}, option);
var total = imgArr.length;
var loaded = 0;
for(var i in imgArr) {
imgList.push($("<img />")
.attr("src", imgArr[i])
.load(function() {
loaded++;
if(loaded == total) {
setting.loaded_all(loaded, total);
}
})
);
}
}
});
})(jQuery);
$(function() {
$.preload([
"logo.png",
"img-1.png",
"img-2.png"
], {
loaded_all: function(loaded, total) {
$( "#preload" ).fadeOut();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment