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
2010-05-26 13:31:33
Wrong. The window height includes chrome elements like toolbars and menus.
SLaks
2010-05-26 13:32:52
Ah yes I actually meant to type viewport height, my bad.
CharlesLeaf
2010-05-26 13:40:32
+3
A:
Like this:
if (document.documentElement.scrollHeight === document.documentElement.clientHeight) {
//There is no vertical scrollbar
}
This doesn't work in IE
SLaks
2010-05-26 13:32:16
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...
Dan Heberden
2010-05-26 14:24:48