This question already has an answer here:
- How can I check if a scrollbar is visible? 17 answers
I want to detect the presence of a scroll bar in a DIV using jQuery. I was thinking to use $('div').scrollTop()
but that returns 0 in both cases when the scroll bar is at the top and when there is no scroll bar at all.
Any ideas guys?
example:
I will revise what bobince mentioned above since you are asking for jQuery
This is because
scrollHeight
andscrollWidth
are DOM properties.Assuming
overflow
on the div isauto
:Well I ended up finding a solution by doing the following:
Wrap the content that grows with a DIV, then I detect if a (vertical) scroll bar is present by comparing the height of
wrapperDiv
with the height ofcontainerDiv
(which normally has the scroll bar if the content is too large).If the height of
wrapperDiv
is bigger than the height ofcontainerDiv
then there is a scroll bar, if it is smaller, then there is no scroll bar.