Check whether HTML element has scrollbars

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

    none of this answers are correct. you have to use this :

    var div = document.getElementById('container_div_id');
    
    var hasHorizontalScrollbar = (div.offsetWidth > div.clientWidth);
    var hasVerticalScrollbar = (div.offsetHeight > div.clientHeight);
    

提交回复
热议问题