If you're looking to create your own version of Modernizr on a budget, it's definitely possible. However, my recommendation is to organize all the checks within a browser validation object for simplicity. Here's how I approach it:
// Determine browser capabilities
var browser = {
'3d': testCss('perspective', 'Perspective'),
'addEventListener': !!window.addEventListener,
'animations': testCss('animationName', 'AnimationName'),
'canvas': !!window.CanvasRenderingContext2D,
'gradients': testCss('backgroundImage', '', 'background-image:linear-gradient(black,white),radial-gradient(black,white)'),
'svg': !!(document.createElementNS && document.createElementNS('http://www.w3.org/2000/svg','svg').createSVGRect),
'touch': !!('ontouchstart' in window || (window.DocumentTouch && document instanceof DocumentTouch) || navigator.msMaxTouchPoints),
'transitions': testCss('transitionProperty', 'Transition'),
'vw': testCss('width', '', 'width:100vw')
};
function testCss(sPropStandard, sPropPrefixed, sCss) {
var isSupported = false;
if (sCss===undefined) {
// Check property support
var aProps = [
sPropStandard,
'Webkit' + sPropPrefixed,
'Moz' + sPropPrefixed,
'ms' + sPropPrefixed,
'O' + sPropPrefixed
];
for (var i=0; i<aProps.length; ++i) {
if (aProps[i] in document.documentElement.style) {
isSupported = true;
break;
}
}
} else {
// Check value support
var el = document.createElement('temp');
el.style.cssText = sCss;
isSupported = el.style[sPropStandard]!=='';
delete el;
}
return isSupported;
}
With this setup, you can easily determine if the browser supports CSS3 gradients like so:
if (browser.gradients) {
// Implementation for browsers that support gradients
}
Similarly, for checking SVG support in the browser:
if (browser.svg) {
// Implement specific actions for SVG-supported browsers
}