Created
June 6, 2022 04:55
-
-
Save shu1/c95bfeff92f44dae24c64003906c360b to your computer and use it in GitHub Desktop.
getBoundingClientRect
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
#div_1 { | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
background: red; | |
} | |
@media (min-aspect-ratio: 16/9) { | |
#div_1 { | |
width: calc(1600vh / 9); | |
height: 100vh; | |
} | |
} | |
@media (max-aspect-ratio: 16/9) { | |
#div_1 { | |
width: 100vw; | |
height: calc(900vw / 16); | |
} | |
} |
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
<div id="div_1"></div> |
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
window.addEventListener('resize', function () { | |
var rect = div_1.getBoundingClientRect(); | |
div_1.textContent = `${rect.left}, ${rect.top}`; | |
}); |
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
{"name":"getBoundingClientRect","settings":{},"filenames":["index.html","index.css","index.js"]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment