Skip to content

Instantly share code, notes, and snippets.

@easesu
Created June 24, 2014 15:13
Show Gist options
  • Select an option

  • Save easesu/8f49f34733e2e8545c53 to your computer and use it in GitHub Desktop.

Select an option

Save easesu/8f49f34733e2e8545c53 to your computer and use it in GitHub Desktop.
注册图片加载事件
function bindImageLoadEvent(img, callback) {
// if loaded, directly execute callback
if (img.readyState === "complete" || img.complete) {
callback.apply(img);
return true;
}
// otherwise register event
if (img.readyState) {
img.attachEvent("onreadystatechange", function() {
if (img.readyState === "complete") {
callback.apply(img);
}
});
} else {
img.addEventListener("load", callback, false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment