Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

formula for scrollbar size

// For Specific Element
var horizontalScrollbarSize = ((element.offsetWidth / element.scrollWidth) * element.offsetWidth)
var verticalScrollbarSize = ((element.offsetHeight / element.scrollHeight) * element.offsetHeight)

console.log(horizontalScrollbarSize); // Note: This values neglect the height
console.log(verticalScrollbarSize);   // or width of the scrollbar arrows

// For Body
var horizontalScrollbarSize = ((document.body.offsetWidth / document.body.scrollWidth) * document.body.offsetWidth)
var verticalScrollbarSize = ((document.body.offsetHeight / document.body.scrollHeight) * document.body.offsetHeight)

console.log(horizontalScrollbarSize); // Note: This values neglect the height
console.log(verticalScrollbarSize);   // or width of the scrollbar arrows
 
PREVIOUS NEXT
Tagged: #formula #scrollbar #size
ADD COMMENT
Topic
Name
3+6 =