Created
January 11, 2012 21:22
-
-
Save romaricpascal/1596834 to your computer and use it in GitHub Desktop.
A modernizr test to see if browser adds scrollbar on "overflow: scroll" elements
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
/** | |
* Test detecting if scrollbars are available | |
* on overflow-scroll elements. | |
*/ | |
Modernizr.addTest('overflowscroll',function(){ | |
var container = document.createElement('div'); | |
container.style.cssText= 'height: 200px; width: 400px; overflow:scroll'; | |
var content = document.createElement('div'); | |
content.style.cssText= 'height: 400px;'; | |
container.appendChild(content); | |
var fake = false, | |
root = document.body || (function () { | |
fake = true; | |
return document.documentElement.appendChild(document.createElement('body')); | |
}()); | |
var oldCssText = root.style.cssText; | |
root.style.cssText = 'padding:0;margin:0'; | |
root.appendChild(container); | |
var result = container.clientWidth != container.offsetWidth; | |
root.removeChild(container); | |
root.style.cssText = oldCssText; | |
if (fake) { | |
document.documentElement.removeChild(root); | |
} | |
return result; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment