Last active
August 29, 2015 14:17
-
-
Save rsslldnphy/d08f6279148b137e7618 to your computer and use it in GitHub Desktop.
Get the scrollbar width
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
;; Adapted from http://stackoverflow.com/a/8079681 | |
(defonce scrollbar-width | |
(let [inner (.createElement js/document "p") | |
outer (.createElement js/document "div")] | |
(doto (.-style inner) | |
(aset "width" "100%") | |
(aset "height" "500px")) | |
(doto (.-style outer) | |
(aset "position" "absolute") | |
(aset "top" "0px") | |
(aset "left" "0px") | |
(aset "visibility" "hidden") | |
(aset "background" "red") | |
(aset "width" "200px") | |
(aset "height" "150px") | |
(aset "overflow" "hidden")) | |
(.appendChild outer inner) | |
(.appendChild (.-body js/document) outer) | |
(let [w1 (.-offsetWidth inner) | |
_ (aset (.-style outer) "overflow" "scroll") | |
w2 (.-offsetWidth inner) | |
w2 (if (= w1 w2) (.-clientWidth outer) w2)] | |
(.removeChild (.-body js/document) outer) | |
(- w1 w2)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment