Skip to content

Instantly share code, notes, and snippets.

@nishinoshake
Last active August 18, 2016 06:19
Show Gist options
  • Save nishinoshake/4d8d9fd47701be8e7f94 to your computer and use it in GitHub Desktop.
Save nishinoshake/4d8d9fd47701be8e7f94 to your computer and use it in GitHub Desktop.
jQueryで画像のプリロード
## プロパティcompleteとは
var loadImage = function(img) {
var defer = new $.Deferred();
$(img).on('load', function() {
defer.resolve(this);
}).each(function() {
if ( this.complete ) {
defer.resolve(this);
}
});
return defer.promise();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment