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

Invisibility evaluate accurately #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions blazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@
}

function loadElement(ele, force, options) {
// if element has src attribute but doesn't have width or height,
// the reason may be that the palceholder image has not yet loaded,
// so bind this function to its load event to evaluate accurately.
if (ele.getAttribute('src') && (ele.offsetWidth == 0 || ele.offsetHeight == 0)) {
var onLoadHandlerTemp = function() {
unbindEvent(ele, 'load', onLoadHandlerTemp);
loadElement(ele, force, options);
};
bindEvent(ele, 'load', onLoadHandlerTemp);
return;
}
// if element is visible, not loaded or forced
if (!hasClass(ele, options.successClass) && (force || options.loadInvisible || (ele.offsetWidth > 0 && ele.offsetHeight > 0))) {
var dataSrc = ele.getAttribute(_source) || ele.getAttribute(options.src); // fallback to default 'data-src'
Expand Down