By Sam Deering

jQuery Check if Vertical Scroll is Present

By Sam Deering
Help us help you! You'll get a... FREE 6-Month Subscription to SitePoint Premium Plus you'll go in the draw to WIN a new Macbook SitePoint 2017 Survey Yes, let's Do this It only takes 5 min

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;
Login or Create Account to Comment
Login Create Account
Get the latest in JavaScript, once a week, for free.