Skip to content

Instantly share code, notes, and snippets.

@abhianair
Created March 25, 2021 03:58
Show Gist options
  • Save abhianair/79f345c4e6c64fc2dd929578511dc98c to your computer and use it in GitHub Desktop.
Save abhianair/79f345c4e6c64fc2dd929578511dc98c to your computer and use it in GitHub Desktop.
Alert when div is visible during scrolling
// hide the navbar when reached bottom
window.addEventListener('scroll', function() {
var element = document.querySelector('.site-footer');
var position = element.getBoundingClientRect();
// checking whether fully visible
if(position.top >= 0 && position.bottom <= window.innerHeight) {
// console.log('Element is fully visible in screen');
}else{
$('.navbar').slideDown();
}
// checking for partial visibility
if(position.top < window.innerHeight && position.bottom >= 0) {
// console.log('Element is partially visible in screen');
}else{
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment