Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To find out if a div has a scrollbar

If a div is set as overflow:auto, how can I find out (using plain JS) if a scrollbar (Vertical / Horizontal) has been rendered?

like image 909
KJ Saxena Avatar asked Nov 20 '09 06:11

KJ Saxena


People also ask

How do I check if a scroll is present?

To check if a scrollbar is present for an element, we can compare the scrollHeight value with its clientHeight value, both are in pixels.

Does 100vw include scrollbar?

Many assume that width: 100vw is the same as width: 100% . This is true on a page that doesn't scroll vertically, but what you might not realize is that the viewport actually includes the scrollbars, too.

How do I show scrollbars?

Show scroll bars in Word and Excel for WindowsClick File > Options. On the Advanced tab, scroll to the Display section. Select Show horizontal scroll bar and Show vertical scroll bar, and then click OK.


1 Answers

Check if clientHeight is smaller than scrollHeight.

like image 187
rahul Avatar answered Oct 03 '22 03:10

rahul