This has been incorporated in a small library.
Last active
June 30, 2020 13:53
-
-
Save danburzo/994748cd383ddc88f19917b4e38ef771 to your computer and use it in GitHub Desktop.
Find elements that poke outside window bounds
This file contains 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
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