Skip to content

Instantly share code, notes, and snippets.

@fregante
Created October 10, 2012 12:25
Show Gist options
  • Save fregante/3865283 to your computer and use it in GitHub Desktop.
Save fregante/3865283 to your computer and use it in GitHub Desktop.
Check for scrollbar visibility and load jScrollPane if scrollbars are visible
//This example requires YepNope or Modernizr.load (which are the same) and jQuery
var customScroll = (function () {
var customScroll = {};
customScroll.selector = ".entry-gallery, .entry-main";
customScroll.init = function () {
try {
(yepnope || Modernizr.load)({
test: customScroll.hasScrollBars,
yep: 'res/jscrollpane.js',
callback: customScroll.set
});
} catch (e) {}
}
customScroll.set = function () {
$(function () {
$(customScroll.selector).jScrollPane({
animateScroll: true
});
});
}
customScroll.hasScrollBars = (function () {
var d = document,
body = d.body,
css = 'width: 100px; height: 100px; overflow: scroll; position: absolute; top: -9999px;',
div = d.createElement("div");
div.setAttribute('style', css);
body.appendChild(div);
var scrollbarWidth = div.offsetWidth - div.clientWidth;
body.removeChild(div);
return scrollbarWidth > 1;
}());
customScroll.init();
return customScroll;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment