Skip to content

Instantly share code, notes, and snippets.

@varemenos
Last active December 29, 2015 12:19
Show Gist options
  • Save varemenos/7669380 to your computer and use it in GitHub Desktop.
Save varemenos/7669380 to your computer and use it in GitHub Desktop.
Check if calc() is supported by your browser
// returns true if your browser supports calc()
myapp.checkCalc = function (prefix = '') {
var el = document.createElement('div');
el.style.cssText = prefix + 'width: calc(1px);';
return !!el.style.length;
};
// returns true if your browser supports any version of calc(), prefixed or not
myapp.checkAllCalc = function (prefix = '') {
return myapp.checkCalc('-webkit-') || myapp.checkCalc('-moz-') || myapp.checkCalc();
};
myapp.checkCalc('-webkit-'); // check webkit prefixed support
myapp.checkCalc('-moz-'); // check moz prefixed support
myapp.checkCalc(); // check unprefixed/spec support
myapp.checkAllCalc(); // or all together
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment