Answers for "execute a function if element in view"

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 "execute a function if element in view"

Browse Popular Code Answers by Language