开发者

How to know if the scrollbars has appeared in browser (jQuery)?

开发者 https://www.devze.com 2023-01-01 06:58 出处:网络
I need to know, whet开发者_C百科her a vertical scrollbar has appeared or not in browser window. Is it possible using jQuery or any other way?Like this:

I need to know, whet开发者_C百科her a vertical scrollbar has appeared or not in browser window. Is it possible using jQuery or any other way?


Like this:

if (document.documentElement.scrollHeight === document.documentElement.clientHeight) {
    //There is no vertical scrollbar
}

This doesn't work in IE


This is an old post but I finally got the code that also works on IE7. Hope this can help someone.

var hasScrollbar = $('body').outerHeight() > $(window).height();


Compare the document height with the window height. If it's more there's probably a scrollbar unless you disabled it.

0

精彩评论

暂无评论...
验证码 换一张
取 消