Skip to content

Instantly share code, notes, and snippets.

@nandaleite
Last active October 26, 2018 17:45
Show Gist options
  • Select an option

  • Save nandaleite/8e72eb5c7c2c38d292b2950807f0543d to your computer and use it in GitHub Desktop.

Select an option

Save nandaleite/8e72eb5c7c2c38d292b2950807f0543d to your computer and use it in GitHub Desktop.
Detect when footer is visible
function intersectionCallback() {
console.log('target is visible!');
}
window.addEventListener('load', function(){
var wrapper = document.querySelector('#wrapper');
var options = {
root: null,
rootMargin: '0px',
threshold: 0
}
var observer = new IntersectionObserver(intersectionCallback, options);
var target = document.querySelector('#footer');
observer.observe(target);
// Scroll to the starting position
document.scrollingElement.scrollTop = wrapper.getBoundingClientRect().top + window.scrollY;
});
// More details at https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment