Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix picture serve multi images issue #108

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 17 additions & 12 deletions blazy.js
Expand Up @@ -179,7 +179,6 @@
var isImage = equal(ele, 'img');
// Image or background image
if (isImage || ele.src === undefined) {
var img = new Image();
// using EventListener instead of onerror and onload
// due to bug introduced in chrome v50
// (https://productforums.google.com/forum/#!topic/chrome/p51Lk7vnP2o)
Expand All @@ -194,13 +193,6 @@
if (isImage) {
setSrc(ele, src); //src
handleSource(ele, _attrSrcset, options.srcset); //srcset
//picture element
var parent = ele.parentNode;
if (parent && equal(parent, 'picture')) {
each(parent.getElementsByTagName('source'), function(source) {
handleSource(source, _attrSrcset, options.srcset);
});
}
// or background-image
} else {
ele.style.backgroundImage = 'url("' + src + '")';
Expand All @@ -209,9 +201,22 @@
unbindEvent(img, 'load', onLoadHandler);
unbindEvent(img, 'error', onErrorHandler);
};
bindEvent(img, 'error', onErrorHandler);
bindEvent(img, 'load', onLoadHandler);
setSrc(img, src); //preload

//picture element
var parent = ele.parentNode;
if (parent && equal(parent, 'picture')) {
setSrc(ele, src); //src
handleSource(ele, _attrSrcset, options.srcset); //srcset
each(parent.getElementsByTagName('source'), function(source) {
handleSource(source, _attrSrcset, options.srcset);
});
}
else {
var img = new Image();
bindEvent(img, 'error', onErrorHandler);
bindEvent(img, 'load', onLoadHandler);
setSrc(img, src); //preload
}
} else { // An item with src like iframe, unity, simpelvideo etc
setSrc(ele, src);
itemLoaded(ele, options);
Expand Down Expand Up @@ -314,4 +319,4 @@
fn.apply(scope, arguments);
};
}
});
});