Last active
February 11, 2020 17:29
-
-
Save kdzwinel/bd3c88be76920b57057ab742cbecfb5d to your computer and use it in GitHub Desktop.
DevTools snippet that lets you focus on a single element during developement
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() { | |
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); | |
})(); |
Author
kdzwinel
commented
Sep 21, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment