Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jack2jm/4b21bdd61aad9f5f3d32b2a73a7e341d to your computer and use it in GitHub Desktop.
Save jack2jm/4b21bdd61aad9f5f3d32b2a73a7e341d to your computer and use it in GitHub Desktop.
This code can check view is in block or not - IntersectionObserver
var get_started_block = document.getElementById("get-started");
var float_button = document.getElementById("float-btn");
function handler(entries, observer) {
for (entry of entries) {
if (entry.isIntersecting) {
float_button.style.display = "none";
}else{
float_button.style.display = "block";
}
}
}
/* By default, invokes the handler whenever:
1. Any part of the target enters the viewport
2. The last part of the target leaves the viewport */
let observer = new IntersectionObserver(handler);
observer.observe(get_started_block);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment