Answers for "see if element is in view"

1

js check if element into view

function isInViewport(element) {
    const rect = element.getBoundingClientRect();
    return (
        rect.top >= 0 &&
        rect.left >= 0 &&
        rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
        rect.right <= (window.innerWidth || document.documentElement.clientWidth)
    );
}
Posted by: Guest on April-01-2021
1

execute a function if element in view

var counter;

window.onscroll = inView;
counter = document.getElementById('counter');
function inView() {
    if (counter.getBoundingClientRect().top <= window.innerHeight) {
        console.log('IN VIEW');
    }
}
Posted by: Guest on May-23-2021

Code answers related to "see if element is in view"

Code answers related to "Javascript"

Browse Popular Code Answers by Language