Check whether HTML element has scrollbars

前端 未结 11 2169
北海茫月
北海茫月 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:36

    I found this somewhere a couple of weeks ago. It worked for me.

    var div = document.getElementById('container_div_id');
    
    var hasHorizontalScrollbar = div.scrollWidth > div.clientWidth;
    var hasVerticalScrollbar = div.scrollHeight > div.clientHeight;
    
    /* you'll get true/false */
    

提交回复
热议问题