Skip to content

Instantly share code, notes, and snippets.

@janwirth
Created August 10, 2019 13:36
Show Gist options
  • Save janwirth/6a2374e13310fba4354fb2b57572ac2b to your computer and use it in GitHub Desktop.
Save janwirth/6a2374e13310fba4354fb2b57572ac2b to your computer and use it in GitHub Desktop.
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