Skip to content

Commit

Permalink
Invisibility evaluate accurately
Browse files Browse the repository at this point in the history
  • Loading branch information
vinzid committed Oct 5, 2016
1 parent 6f3c3b6 commit aff6163
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions blazy.js
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

0 comments on commit aff6163

Please sign in to comment.