-
-
Save crates/861a34fef4f7955700241032b7be426f to your computer and use it in GitHub Desktop.
DevTools snippet that lets you focus on a single element during developement
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() { | |
| function hideEvertyhingAround($el) { | |
| const $parent = $el.parentElement; | |
| $parent.style.transition = 'background-color 150ms ease-in'; | |
| $parent.style.backgroundColor = 'white'; | |
| $parent.childNodes.forEach($child => { | |
| if($child !== $el && $child.style) { | |
| $child.style.transition = 'opacity 150ms ease-in'; | |
| $child.style.opacity = '0'; | |
| } | |
| }); | |
| if($parent.parentElement) { | |
| hideEvertyhingAround($parent); | |
| } | |
| } | |
| function updatePosition() { | |
| const windowWidth = window.innerWidth; | |
| const windowHeight = window.innerHeight; | |
| const fixX = (windowWidth/2 - elBCR.width/2) - elBCR.left; | |
| const fixY = (windowHeight/2 - elBCR.height/2) - elBCR.top; | |
| document.body.style.transition = 'transform 150ms 150ms ease-in'; | |
| document.body.style.transform = `translate3d(${fixX}px, ${fixY}px, 0)`; | |
| } | |
| const $el = $0; | |
| const elBCR = $el.getBoundingClientRect(); | |
| document.body.style.height = '100vh'; | |
| document.body.style.width = '100vw'; | |
| document.body.style.overflow = 'hidden'; | |
| hideEvertyhingAround($el); | |
| updatePosition(); | |
| window.addEventListener("resize", updatePosition); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment