From abc3620a875916e9e08769f688b39461e6c642c1 Mon Sep 17 00:00:00 2001 From: Mouad Date: Tue, 28 May 2019 04:23:14 +0000 Subject: [PATCH] Fix visibility --- jquery.lazy.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/jquery.lazy.js b/jquery.lazy.js index e97bf95..a5c3389 100644 --- a/jquery.lazy.js +++ b/jquery.lazy.js @@ -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); } } @@ -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 @@ -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(); @@ -673,6 +688,7 @@ } } + /** * lazy plugin class constructor * @constructor @@ -869,4 +885,4 @@ $(window).on('load', function() { windowLoaded = true; }); -})(window); \ No newline at end of file +})(window);