Detect Whether a DOM Element Has a Visible Scrollbar
Join the DZone community and get the full member experience.
Join For Freewebkit browsers, especially in mac osx, hide the scrollbar intelligently when not in use. this feature improves the look and feel of the browser. but for the designers, sometimes this can be a pain because they may need to alter the design based on the visibility of the scrollbar.
here are two simple jquery plugins that can detect the visibility of the scrollbar for a given dom element:
for horizontal scrollbars
(function($) { $.fn.hashorizontalscrollbar = function() { return this.get(0) ? this.get(0).scrollwidth > this.innerwidth() : false; } })(jquery);
for vertical scrollbars
(function($) { $.fn.hasverticalscrollbar = function() { return this.get(0) ? this.get(0).scrollheight > this.innerheight() : false; } })(jquery);
you can use it like this:
if($("#element").hasverticalscrollbar()){ //do whatever you'd like to }
source and idea:
this
stackoverflow discussion.
Published at DZone with permission of Hasin Hayder, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Incident Response Guide
-
Payments Architecture - An Introduction
-
Demystifying SPF Record Limitations
-
DevOps Midwest: A Community Event Full of DevSecOps Best Practices
Comments