views:

298

answers:

3

I need to know, whether a vertical scrollbar has appeared or not in browser window. Is it possible using jQuery or any other way?

A: 

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

CharlesLeaf
Wrong. The window height includes chrome elements like toolbars and menus.
SLaks
Ah yes I actually meant to type viewport height, my bad.
CharlesLeaf
+3  A: 

Like this:

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

This doesn't work in IE

SLaks
A: 

And if you're looking to 'detect' this change, you might want to use .scroll() or .bind('scroll', function() { to then check if it was a vertical scroll...

http://api.jquery.com/scroll/

Dan Heberden