Detect if a page has a vertical scrollbar?

后端 未结 13 1799
旧时难觅i
旧时难觅i 2020-11-28 02:17

I just want some simple JQ/JS to check if the current page/window (not a particular element) has a vertical scrollbar.

Googling gives me stuff that seems overly comp

13条回答
  •  遥遥无期
    2020-11-28 02:58

    Other solutions didn't work in one of my projects and I've ending up checking overflow css property

    function haveScrollbar() {
        var style = window.getComputedStyle(document.body);
        return style["overflow-y"] != "hidden";
    }
    

    but it will only work if scrollbar appear disappear by changing the prop it will not work if the content is equal or smaller than the window.

提交回复
热议问题