Created
November 7, 2017 02:58
-
-
Save Shuumatsu/80d1d331c3e80c9d2f37a1a698ecc263 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
export const eventName = 'in view' | |
export const tagName = 'inview-observer' | |
const io = new IntersectionObserver((entries, observer) => { | |
entries.forEach(entry => { | |
const target = entry.target | |
target.dispatchEvent(new Event('in view')) | |
}) | |
}, { threshold: 0.25 }) | |
class InViewObserver extends HTMLElement { | |
connectedCallback() { | |
io.observe(this) | |
} | |
disconnectedCallback() { | |
io.unobserve(this) | |
} | |
} | |
customElements.define( | |
tagName, | |
InViewObserver, | |
{ extends: 'div' } | |
) | |
export default InViewObserver |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment