How can I check if a scrollbar is visible?

后端 未结 19 2602
情话喂你
情话喂你 2020-11-22 14:39

Is it possible to check the overflow:auto of a div?

For example:

HTML

19条回答
  •  粉色の甜心
    2020-11-22 15:25

    There's two area sizes to consider, the window and the html. If the html width, for example, is greater than window width then a scroll bar may be present on the user interface. So it's a matter of reading the window proportions and the html proportions and doing the basic math.

    As for displaying an arrow overlaid atop the page, that's done with a simple classlist toggle, e.g. .hidden{display:none}

    Here's a crossbrowser method for getting these proportions. (credit W3 Schools)

    || document.body.clientWidth;
    
    var h = window.innerHeight || document.documentElement.clientHeight ||
    document.body.clientHeight; ```
    

提交回复
热议问题