Click here to Skip to main content
Click here to Skip to main content

Detect Scrollbars Presence

, 18 Sep 2007
Rate this:
Please Sign up or sign in to vote.
Detect Scrollbars Presence

Introduction

This javascript will help you to detect presence of scrollbars (either x or y or both) for a div tag. Just pass the parameters (div Id and Aces i.e. which side of scrollbar x or y or both you want to detect) to the javascript function and you will know whether the scroll bar exist or not. The second parameter (Aces) is optional, you can leave this blank if you are not sure which scrollbar could exist and you want to detect whichever (x or y) scrollbar is exist. The attached sample file detect_scrollbars_div.aspx will show few examples. This javascript was only tested on Microsoft Internet Explorer version 6.0 in VWD 2005 Express Edition environment. This is a free javascript distributed in the hope that it will be useful but without any warranty.

Background

I wanted to show customized scrollbars left/right buttons if the scrollbars exist. The reason of showing the customized scrollbars buttons is that my div has a limited size and show dynamic contents. In some case the contents are wider than the division width. If I show the standard scrollbar (overflow:auto) that mess up my div look. Another reason is that I only wanted to show the customized scrollbars left/right buttons only if the scrollbar is presence otherwse the customized left/right buttons also disappear. Therefore I wrote this simple and show javascript to detect if the scrollbar is exist, if yes then the customized scrollbar buttons appear.

Using the code

The javascript is very simple and straight forward. Looking at the code you will know how to use it. Simply pass the parameters div.id and which side of scrollbar you want to check. If you are not sure which scrollbar could exist just pass the div.id to the javascript function.

Points of Interest

Cool and simple coding.

History

Created by: Muhammad Shoaib

Created on: 18 Sept 2007

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

No Biography provided

Comments and Discussions

 
QuestionSuggestion Pinmemberphilipp.germany24-Jan-12 2:30 
GeneralI like it Pinmembercmschick8-Feb-09 4:32 
GeneralCool PinmemberTom Hawkins11-Oct-07 13:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 19 Sep 2007
Article Copyright 2007 by Muhammad Shoaib Patel
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid