Skip to content

Instantly share code, notes, and snippets.

@agneym
Created June 30, 2018 16:57
Show Gist options
  • Save agneym/c3d8b8e429fbfc4622fb1a88924a6257 to your computer and use it in GitHub Desktop.
Save agneym/c3d8b8e429fbfc4622fb1a88924a6257 to your computer and use it in GitHub Desktop.
var observer = new IntersectionObserver(changes => {
for (const change of changes) {
console.log(change.time); // Timestamp when the change occurred
console.log(change.rootBounds); // Unclipped area of root
console.log(change.boundingClientRect); // target.boundingClientRect()
console.log(change.intersectionRect); // boundingClientRect, clipped by its containing block ancestors, and intersected with rootBounds
console.log(change.intersectionRatio); // Ratio of intersectionRect area to boundingClientRect area
console.log(change.target); // the Element target
}
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment