Created
September 27, 2018 00:22
-
-
Save j-/22bcf8f182c2e511b7e6f486a9dbee15 to your computer and use it in GitHub Desktop.
Easily measure scrollbar width and height
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="outer"> | |
<div id="inner"> | |
</div> | |
</div> | |
<style> | |
#outer { | |
width: 2em; | |
height: 2em; | |
overflow: scroll; | |
border: 1px solid red; | |
position: relative; | |
} | |
#inner { | |
width: 4em; | |
height: 4em; | |
border: 1px solid blue; | |
position: relative; | |
bottom: 0; | |
right: 0; | |
} | |
</style> | |
<script> | |
const outerRect = document.getElementById('outer').getClientRects()[0]; | |
const innerRect = document.getElementById('inner').getClientRects()[0]; | |
const scrollWidth = outerRect.right - innerRect.right; | |
const scrollHeight = outerRect.bottom - innerRect.bottom; | |
console.log(scrollWidth, scrollHeight); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment