Created
April 29, 2011 19:00
-
-
Save ZeeAgency/948808 to your computer and use it in GitHub Desktop.
CSS Scrollbar detection Modernizr plugin
This file contains hidden or 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
// Works only with Modernizr 1.8pre+ | |
Modernizr.addTest('cssscrollbar', function() { | |
// Tested Element | |
var test = document.createElement('div'), | |
// Fake body | |
fake = false, | |
root = document.body || (function () { | |
fake = true; | |
return document.documentElement.appendChild(document.createElement('body')); | |
}()), | |
property = 'scrollbar{width:0px;}'; | |
// Force scrollbar | |
test.id = '__sb'; | |
test.style.overflow = 'scroll'; | |
test.style.width = '40px'; | |
// Apply scrollbar style for all vendors | |
test.innerHTML = '­<style>#'+Modernizr._prefixes.join(property+' #__sb::').split('#').slice(1).join('#')+property+'</style>'; | |
root.appendChild(test); | |
// If css scrollbar is supported, than the scrollWidth should not be impacted | |
var ret = test.scrollWidth == 40; | |
// Cleaning | |
document.body.removeChild(test); | |
if (fake) { | |
document.documentElement.removeChild(root); | |
} | |
return ret; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nope. this is for the ability to style scrollbars.
@ZeeAgency can you give us a pull request for this in the modernizr feature-detects/ folder? thanks!