Created
October 10, 2022 00:30
-
-
Save luislobo14rap/1dc98accccab24c0f2374f0b12175ca9 to your computer and use it in GitHub Desktop.
getScrollbarSize.js
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
// getScrollbarSize.js v1 | |
const cssText = '#scrollbar-size{height:99px;overflow:scroll;position:absolute;top:-9999px;width:99px}', | |
head = document.getElementsByTagName('head')[0] || document.body.parentNode.children[0], | |
style = document.createElement('style'), | |
scrollSizeDiv = document.createElement('div'), | |
scrollbarSize = undefined; | |
style.setAttribute('type', 'text/css'); | |
style.setAttribute('rel', 'stylesheet'); | |
if (!('styleSheet' in style)) { | |
style.appendChild(document.createTextNode(cssText)); | |
} else { | |
style.styleSheet.cssText = cssText; | |
}; | |
head.appendChild(style); | |
scrollSizeDiv.id = 'scrollbar-size'; | |
document.body.appendChild(scrollSizeDiv); | |
scrollbarSizeX = scrollSizeDiv.offsetWidth - scrollSizeDiv.clientWidth; | |
scrollbarSizeY = scrollSizeDiv.offsetHeight - scrollSizeDiv.clientHeight; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment