Skip to content

Instantly share code, notes, and snippets.

@danburzo
Last active June 30, 2020 13:53
Show Gist options
  • Save danburzo/994748cd383ddc88f19917b4e38ef771 to your computer and use it in GitHub Desktop.
Save danburzo/994748cd383ddc88f19917b4e38ef771 to your computer and use it in GitHub Desktop.
Find elements that poke outside window bounds
function* poking() {
let els = [...document.querySelectorAll('*')];
for (let el of els) {
let rect = el.getBoundingClientRect();
if (rect.x + rect.width > window.innerWidth) {
yield el;
}
}
};
// Usage:
let elements = poking();
elements.next().value // First matching element...
elements.next().value // Next matching element...
// and so on, until
elements.next().value // undefined (i.e. finished)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment