function elementInView(target) { // selects target div const targetDiv = document.querySelector(target); // gets target position from top of viewport const targetPosition = targetDiv.getBoundingClientRect(); switch (true) { case targetPosition.top > 1: console.log('hidden'); break; case targetPosition.top <= 0 && targetPosition.bottom >= 0: console.log('visible'); break; case targetPosition.bottom < 0: console.log('hidden'); break; default: break; } } // add function to document.addEventListener('scroll')