Skip to content

Instantly share code, notes, and snippets.

@cuing
Created December 18, 2013 02:33
Show Gist options
  • Save cuing/8016430 to your computer and use it in GitHub Desktop.
Save cuing/8016430 to your computer and use it in GitHub Desktop.
图片加载完成
// script 1
var img = document.getElementById('image1');
img.addEventListener('load', function() {
// loaded handing
})
img.addEventListener('error', function() {
// error handing
})
// 上面代码,如果图片在调用事件前加载完成,则不会调用改方法
var img1 = document.getElementById('image1');
function loaded() {
}
if (img1.complete) {
loaded();
} else {
img1.addEventListener('load', function() {
// loaded handing
})
}
img1.addEventListener('error', function() {
// error handing
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment