JSFiddle - React, Tailwind, and code Playground
by wisegorilla
JavaScript
// Start observing visbility of element. On change, the
// the callback is called with Boolean visibility as
// argument:
function x() {
console.log('opserved');
}
function respondToVisibility(element, callback) {
var options = {
root: document.documentElement,
};
var observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
callback(entry.intersectionRatio > 0);
});
}, options);
observer.observe(element);
}
respondToVisibility();