Detect if a page has a vertical scrollbar?

后端 未结 13 1775
旧时难觅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 03:20
    $(document).ready(function() {
        // Check if body height is higher than window height :)
        if ($("body").height() > $(window).height()) {
            alert("Vertical Scrollbar! D:");
        }
    
        // Check if body width is higher than window width :)
        if ($("body").width() > $(window).width()) {
            alert("Horizontal Scrollbar! D:<");
        }
    });
    
    0 讨论(0)
提交回复
热议问题