From dc1c1b77201b377b38e74f7a0b7a5464dab83061 Mon Sep 17 00:00:00 2001 From: mizuide Date: Wed, 25 Oct 2017 12:08:08 +0900 Subject: [PATCH 1/2] stopped loading img which is in "display:none" when layzr checks "getBoundingClientRect", element which is nod displayed returns 0 as getBoundingClientRect().top --- src/layzr.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/layzr.js b/src/layzr.js index 68b42ea..01d6369 100644 --- a/src/layzr.js +++ b/src/layzr.js @@ -74,8 +74,9 @@ export default (options = {}) => { const nodeBot = nodeTop + node.offsetHeight const offset = (settings.threshold / 100) * windowHeight + const nodeRect = node.getBoundingClientRect(); - return (nodeBot >= viewTop - offset) && (nodeTop <= viewBot + offset) + return (nodeRect.width != 0) && (nodeBot >= viewTop - offset) && (nodeTop <= viewBot + offset) } // source helper From b8de47cc2c531fcea1fb228f30a67b45d4f67cf0 Mon Sep 17 00:00:00 2001 From: mizuide Date: Wed, 25 Oct 2017 16:38:07 +0900 Subject: [PATCH 2/2] fixed small mistakes --- src/layzr.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/layzr.js b/src/layzr.js index 01d6369..2a2aa6d 100644 --- a/src/layzr.js +++ b/src/layzr.js @@ -74,9 +74,9 @@ export default (options = {}) => { const nodeBot = nodeTop + node.offsetHeight const offset = (settings.threshold / 100) * windowHeight - const nodeRect = node.getBoundingClientRect(); + const nodeRect = node.getBoundingClientRect() - return (nodeRect.width != 0) && (nodeBot >= viewTop - offset) && (nodeTop <= viewBot + offset) + return (nodeRect.width !== 0) && (nodeBot >= viewTop - offset) && (nodeTop <= viewBot + offset) } // source helper