update intersection support handling
This commit is contained in:
parent
7f1b138304
commit
b9bcde8dd9
|
@ -1,8 +1,6 @@
|
||||||
(function() {
|
(function() {
|
||||||
window.addEventListener('DOMContentLoaded', event => {
|
window.addEventListener('DOMContentLoaded', event => {
|
||||||
if (!!window.IntersectionObserver) {
|
const intersectionSupport = !!window.IntersectionObserver;
|
||||||
document.body.classList.add('supports-intersect');
|
|
||||||
}
|
|
||||||
|
|
||||||
function onScreenHandler(entries) {
|
function onScreenHandler(entries) {
|
||||||
entries.forEach(entry => {
|
entries.forEach(entry => {
|
||||||
|
@ -15,12 +13,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
document.querySelectorAll('.js-onscreen').forEach(el => {
|
document.querySelectorAll('.js-onscreen').forEach(el => {
|
||||||
const options = {
|
if (intersectionSupport) {
|
||||||
rootMargin: '0px',
|
const options = {
|
||||||
threshold: [0, 1],
|
rootMargin: '0px',
|
||||||
};
|
threshold: [0, 1],
|
||||||
const observer = new IntersectionObserver(onScreenHandler, options);
|
};
|
||||||
observer.observe(el);
|
const observer = new IntersectionObserver(onScreenHandler, options);
|
||||||
|
observer.observe(el);
|
||||||
|
el.classList.add('is-observed');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue