Detect If The DIV Have Scroll Bar Or Not
Possible Duplicate: Detecting presence of a scroll bar in a DIV using jQuery? There is markup as below,
Lorem
L
Solution 1:
(function($) {
$.fn.hasScrollBar = function() {
return this.get(0).scrollHeight > this.height();
}
})(jQuery);
$('#my_div1').hasScrollBar(); // returns true if there's a `vertical` scrollbar, false otherwise..
Taken from How can I check if a scrollbar is visible?
Solution 2:
You need to compare scrollHeight
with height
of the element like this:
$('.content').each(function(){
if ($(this)[0].scrollHeight > $(this).height()) {
$(this).addClass('scroll-image');
}
});
Solution 3:
As esailija said, duplicate of: Detecting presence of a scroll bar in a DIV using jQuery?
The solution there was the following
var div= document.getElementById('something'); // need real DOM Node, not jQuery wrapper
var hasVerticalScrollbar= div.scrollHeight>div.clientHeight;
var hasHorizontalScrollbar= div.scrollWidth>div.clientWidth;
Solution 4:
(function($) {
$.fn.hasScrollBar = function() {
return this.get(0).scrollHeight > this.height();
}
})(jQuery);
$('div').hasScrollBar(); //return true if it has one
Post a Comment for "Detect If The DIV Have Scroll Bar Or Not"