Created
March 25, 2021 03:58
-
-
Save abhianair/79f345c4e6c64fc2dd929578511dc98c to your computer and use it in GitHub Desktop.
Alert when div is visible during scrolling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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