Skip to content

Visibility Enhancement #201

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

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
22 changes: 19 additions & 3 deletions jquery.lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@

// bind lazy load functions to scroll and resize event
// noinspection JSUnresolvedVariable
$(config.appendScroll).on('scroll.' + namespace + ' resize.' + namespace, events.e);
$(config.appendScroll).on('scroll.' + namespace + ' resize.' + namespace + ' change mouseenter mouseleave', events.e);
}
}

Expand Down Expand Up @@ -350,7 +350,7 @@
// is not already handled
if (!element.data(handledName) &&
// and is visible or visibility doesn't matter
(!config.visibleOnly || element.is(':visible')) && (
(!config.visibleOnly || _isRendered(element)) && (
// and image source or source set attribute is available
(attribute || element.attr(srcsetAttribute)) && (
// and is image tag where attribute is not equal source or source set
Expand Down Expand Up @@ -661,6 +661,21 @@
return false;
}

function _isRendered(domObj) {
if ((domObj.nodeType != 1) || (domObj == document.body)) {
return true;
}
if (domObj.currentStyle && domObj.currentStyle["display"] != "none" && domObj.currentStyle["visibility"] != "hidden") {
return _isRendered(domObj.parentNode);
} else if (window.getComputedStyle) {
var cs = document.defaultView.getComputedStyle(domObj, null);
if (cs.getPropertyValue("display") != "none" && cs.getPropertyValue("visibility") != "hidden") {
return _isRendered(domObj.parentNode);
}
}
return false;
}

// if event driven or window is already loaded don't wait for page loading
if (config.bind === 'event' || windowLoaded) {
_initialize();
Expand All @@ -673,6 +688,7 @@
}
}


/**
* lazy plugin class constructor
* @constructor
Expand Down Expand Up @@ -869,4 +885,4 @@
$(window).on('load', function() {
windowLoaded = true;
});
})(window);
})(window);