prostoandrei
3/2/2018 - 6:56 AM

isElementInViewport

Check if element is visible in browser viewport

const isElementInViewport = (el) => {
    const rect = el.getBoundingClientRect();

    return rect.bottom > 0 && rect.right > 0 &&
        rect.left < (window.innerWidth || document.documentElement.clientWidth) &&
        rect.top < (window.innerHeight || document.documentElement.clientHeight);
}