jQuery Check if Vertical Scroll is Present

Sam Deering

Simple jQuery code snippet to return true or false to check if the main window vertical scrollbar is present. Useful for firing off an event when a user scrolls to the bottom of a page such as showing related pages.

//checks if vertical scroll is present
//works in FF8 also
verticalScrollPresent: function()
  return (document.documentElement.scrollHeight !== document.documentElement.clientHeight);
//a longer winded version of the above
verticalScrollPresent: function()
  //return (document.documentElement.scrollHeight !== document.documentElement.clientHeight);

  // Get the computed style of the body element
  var cStyle = document.body.currentStyle||window.getComputedStyle(document.body, "");

  // Check the overflow and overflowY properties for "auto" and "visible" values
  hasVScroll = cStyle.overflow == "visible"
               || cStyle.overflowY == "visible"
               || (hasVScroll && cStyle.overflow == "auto")
               || (hasVScroll && cStyle.overflowY == "auto");

  return !hasVScroll;