Created
August 10, 2019 13:36
-
-
Save janwirth/6a2374e13310fba4354fb2b57572ac2b to your computer and use it in GitHub Desktop.
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
class Intersector extends HTMLElement { | |
constructor() { | |
super(); | |
const threshold = 0; | |
var options = { | |
root: this.parentElement, | |
rootMargin: "-40% 0% -59%", | |
threshold: [threshold] | |
}; | |
const callback = (entries, observer) => { | |
entries.forEach(entry => { | |
if (entry.intersectionRatio > threshold) { | |
this.dispatchEvent(new CustomEvent('center', {})); | |
} | |
}); | |
}; | |
var observer = new IntersectionObserver(callback, options); | |
observer.observe(this); | |
}} | |
export const register = () => customElements.define("intersection-observable", Intersector) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment