KyleNumann
4/18/2017 - 6:04 PM

test if scrollbars exist, and get width

test if scrollbars exist, and get width

        var scrollDiv = document.createElement("div");
        scrollDiv.className = "scrollbar-measure";
        scrollDiv.style.cssText = 'width: 100px; height: 100px; overflow: scroll; position: absolute; top: -9999px;';

        document.body.appendChild(scrollDiv);

        // Get the scrollbar width
        var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
        console.log('scrollbar: '+ scrollbarWidth); // Mac:  15

        // Delete the DIV
        document.body.removeChild(scrollDiv);