Given a with a fixed width, I would like its \"active width\" to be constant (in px). By \"active width\" I mean the
Scrollbar width is simply (offsetWidth - clientWidth) in a borderless! element. This function calculates it on the fly and caches the result for further use. No need need for percentage width etc.
var getScrollbarWidth = function() {
var div, width = getScrollbarWidth.width;
if (width === undefined) {
div = document.createElement('div');
div.innerHTML = '';
div = div.firstChild;
document.body.appendChild(div);
width = getScrollbarWidth.width = div.offsetWidth - div.clientWidth;
document.body.removeChild(div);
}
return width;
};