Created
November 7, 2012 16:14
-
-
Save hay/4032527 to your computer and use it in GitHub Desktop.
Check if a browser supports the overflow-scrolling CSS property, optionally with a prefix
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
function hasOverflowScrolling() { | |
var prefixes = ['webkit', 'moz', 'o', 'ms']; | |
var div = document.createElement('div'); | |
var body = document.getElementsByTagName('body')[0]; | |
var hasIt = false; | |
body.appendChild(div); | |
for (var i = 0; i < prefixes.length; i++) { | |
var prefix = prefixes[i]; | |
div.style[prefix + 'OverflowScrolling'] = 'touch'; | |
} | |
// And the non-prefixed property | |
div.style.overflowScrolling = 'touch'; | |
// Now check the properties | |
var computedStyle = window.getComputedStyle(div); | |
// First non-prefixed | |
hasIt = !!computedStyle.overflowScrolling; | |
// Now prefixed... | |
for (var i = 0; i < prefixes.length; i++) { | |
var prefix = prefixes[i]; | |
if (!!computedStyle[prefix + 'OverflowScrolling']) { | |
hasIt = true; | |
break; | |
} | |
} | |
// Cleanup old div elements | |
div.parentNode.removeChild(div); | |
return hasIt; | |
} | |
alert(hasOverflowScrolling()); |
@heaversm newest version of chrome doesn't support that property anymore. This is not a problem of this function.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems to return false for me on newest version of chrome (i.e. - not working properly).