Last active
August 29, 2020 07:09
-
-
Save scsskid/872d44da655d574c78e314fc83dafb95 to your computer and use it in GitHub Desktop.
Detect Scrollbar Width
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
// src: https://davidwalsh.name/detect-scrollbar-width | |
// Create the measurement node | |
var scrollDiv = document.createElement("div"); | |
scrollDiv.className = "scrollbar-measure"; | |
document.body.appendChild(scrollDiv); | |
// Get the scrollbar width | |
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; | |
console.warn(scrollbarWidth); // Mac: 15 | |
// Delete the DIV | |
document.body.removeChild(scrollDiv); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment