$.fn.glow = function(delay = 1000) {
return this.each(function() {
let interval;
const startGlow = () => {
interval = setInterval(() => $(this).toggleClass('glow'), delay);
}
const stopGlow = () => {
clearInterval(interval);
}
$(this).on('mouseenter', stopGlow);
$(this).on('mouseleave', startGlow);
startGlow();
return this;
})
}
$('.glowable').glow();
const onIntersection = (entries) => {
entries.forEach(entry => {
if (entry.intersectionRatio > 0) {
// visible
} else {
// not visible
}
});
};
const observer = new IntersectionObserver(onIntersection);
observer.observe(document.querySelector('#element'));
limit - The maximum number of items to return
offset - The index of the first item to return