Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting presence of a scroll bar in a DIV using jQuery? [duplicate]

Tags:

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?

like image 722
7wp Avatar asked Apr 15 '10 17:04

7wp


1 Answers

Assuming overflow on the div is auto:

var div= document.getElementById('something'); // need real DOM Node, not jQuery wrapper var hasVerticalScrollbar= div.scrollHeight>div.clientHeight; var hasHorizontalScrollbar= div.scrollWidth>div.clientWidth; 
like image 159
bobince Avatar answered Oct 08 '22 16:10

bobince