Created
May 28, 2019 09:29
-
-
Save jack2jm/4b21bdd61aad9f5f3d32b2a73a7e341d to your computer and use it in GitHub Desktop.
This code can check view is in block or not - IntersectionObserver
This file contains 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
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