Click here to Skip to main content
15,887,175 members
Articles / Web Development / ASP.NET
Article

Detect Scrollbars Presence

Rate me:
Please Sign up or sign in to vote.
2.82/5 (4 votes)
18 Sep 20072 min read 38.2K   299   6   3
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


Written By
Malaysia Malaysia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionSuggestion Pin
philipp.germany24-Jan-12 1:30
philipp.germany24-Jan-12 1:30 
GeneralI like it Pin
cmschick8-Feb-09 3:32
cmschick8-Feb-09 3:32 
GeneralCool Pin
Tom Hawkins11-Oct-07 12:15
Tom Hawkins11-Oct-07 12:15 

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

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