From b9bcde8dd977216c34d22ce4a5077df08a9d8ef3 Mon Sep 17 00:00:00 2001 From: ray Date: Thu, 21 May 2020 16:27:00 +0100 Subject: [PATCH] update intersection support handling --- src/js/index.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/js/index.js b/src/js/index.js index 71df099..b67add8 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -1,8 +1,6 @@ (function() { window.addEventListener('DOMContentLoaded', event => { - if (!!window.IntersectionObserver) { - document.body.classList.add('supports-intersect'); - } + const intersectionSupport = !!window.IntersectionObserver; function onScreenHandler(entries) { entries.forEach(entry => { @@ -15,12 +13,15 @@ } document.querySelectorAll('.js-onscreen').forEach(el => { - const options = { - rootMargin: '0px', - threshold: [0, 1], - }; - const observer = new IntersectionObserver(onScreenHandler, options); - observer.observe(el); + if (intersectionSupport) { + const options = { + rootMargin: '0px', + threshold: [0, 1], + }; + const observer = new IntersectionObserver(onScreenHandler, options); + observer.observe(el); + el.classList.add('is-observed'); + } }); }); })();