To find the size of the scroll bar, subtract the element's offset by its client size.
var myDiv = document.getElement...
var verticalScrollBarWidth = myDiv.offsetWidth - myDiv.clientWidth;
var horizontalScrollBarHeight = myDiv.offsetHeight - myDiv.clientHeight;
These are two properties:
Object.defineProperty(HTMLElement, "verticalScrollBarWidth", {
get: function() {
var tmpWidth = HTMLElement.offsetWidth - HTMLElement.clientWidth;
if (tmpWidth > 0)
return tmpWidth;
return -1;
},
set: undefined
});
Object.defineProperty(HTMLElement, "horizontalScrollBarHeight", {
get: function() {
var tmpHeight = HTMLElement.offsetHeight - HTMLElement.clientHeight;
if (tmpHeight > 0)
return tmpHeight;
return -1;
},
set: undefined
});
How to use it:
var myDiv = document.getElement...
var vScrollBarWidth = myDiv.verticalScrollBarWidth;
var hScrollBarWidth = myDiv.horizontalScrollBarHeight;