Last active
December 17, 2020 15:53
-
-
Save cmargroff/eec67393a1cee5fcc79388a597f3066d 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
(function(w, d){ | |
const style = d.createElement('style'); | |
style.innerText = ".oob { outline: 1px solid #f00 !important; }"; | |
d.head.appendChild(style); | |
const nodes = d.querySelectorAll("*"); | |
let vpw = window.innerWidth; | |
w.addEventListener('resize', resize) | |
let timer; | |
function resize(){ | |
w.clearTimeout(timer) | |
timer = w.setTimeout(detect, 400) | |
} | |
function detect() { | |
vpw = window.innerWidth; | |
nodes.forEach(el => { | |
if((el.scrollWidth > vpw || (el.scrollWidth + el.scrollLeft) > vpw) && el.className.indexOf("oob") === -1) { | |
el.className += " oob" | |
console.log(el) | |
} else if( (el.scrollWidth <= vpw && (el.scrollWidth + el.scrollLeft) <= vpw) && el.className.indexOf("oob") !== -1 ) { | |
el.className = el.className.replace(/\s?oob/, '') | |
} | |
}) | |
} | |
detect(); | |
})(window, document) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment