Check whether HTML element has scrollbars

前端 未结 11 2197
北海茫月
北海茫月 2020-11-27 11:58

What\'s the fastest way of checking whether an element has scroll bars?

One thing of course is checking whether element is larger than its viewport, which can easily

11条回答
  •  无人及你
    2020-11-27 12:55

    Try:

    For vertical scroll bar

    el.scrollHeight > el.clientHeight

    For horizontal scrollbar

    el.scrollWidth > el.clientWidth

    I know this works for IE8 and Firefox 3.6+ at least.

提交回复
热议问题