Skip to content

Instantly share code, notes, and snippets.

@hay
Created November 7, 2012 16:14
Show Gist options
  • Save hay/4032527 to your computer and use it in GitHub Desktop.
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
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
Copy link

Seems to return false for me on newest version of chrome (i.e. - not working properly).

@Grsmto
Copy link

Grsmto commented Jun 2, 2013

@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