Skip to content Skip to sidebar Skip to footer

Detect Scrollbar Dynamically

What is wrong with the following code? I need to detect and set width of 1 element based on if another element has scrollbar or not. this seems not working: console.log('print Scro

Solution 1:

Have a look at this:

https://jsfiddle.net/4Lms5uzz/

At first the second div is set to 50 by 50.

If scroll is present in the #rules div, the dimensions of the second will be changed.

Basically the method is divWithScrollbar.clientHeight < divWithScrollbar.scrollHeight

scrollHeight gets the height of the content inside the div and clientHeight get the size of the div.

if the scrollHeight is smaller than scrollHeight, the scrollbar is visible.


Post a Comment for "Detect Scrollbar Dynamically"