update intersection support handling

This commit is contained in:
Ray Elliott 2020-05-21 16:27:00 +01:00
parent 7f1b138304
commit b9bcde8dd9
1 changed files with 10 additions and 9 deletions

View File

@ -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 => {
if (intersectionSupport) {
const options = {
rootMargin: '0px',
threshold: [0, 1],
};
const observer = new IntersectionObserver(onScreenHandler, options);
observer.observe(el);
el.classList.add('is-observed');
}
});
});
})();