Created
October 10, 2012 12:25
-
-
Save fregante/3865283 to your computer and use it in GitHub Desktop.
Check for scrollbar visibility and load jScrollPane if scrollbars are visible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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