Last active
December 29, 2015 12:19
-
-
Save varemenos/7669380 to your computer and use it in GitHub Desktop.
Check if calc() is supported by your browser
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
// 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