Created
June 24, 2014 15:13
-
-
Save easesu/8f49f34733e2e8545c53 to your computer and use it in GitHub Desktop.
注册图片加载事件
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
| 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