modernizr
Version:
Modernizr is a JavaScript library that detects HTML5 and CSS3 features in the user’s browser.
46 lines (41 loc) • 1.74 kB
JavaScript
/*!
{
"name": "CSS Transforms 3D",
"property": "csstransforms3d",
"caniuse": "transforms3d",
"tags": ["css"],
"warnings": [
"Chrome may occassionally fail this test on some systems; more info: https://code.google.com/p/chromium/issues/detail?id=129004"
]
}
!*/
define(['Modernizr', 'testAllProps', 'testStyles', 'docElement', 'test/css/supports'], function(Modernizr, testAllProps, testStyles, docElement) {
Modernizr.addTest('csstransforms3d', function() {
var ret = !!testAllProps('perspective', '1px', true);
var usePrefix = Modernizr._config.usePrefixes;
// Webkit's 3D transforms are passed off to the browser's own graphics renderer.
// It works fine in Safari on Leopard and Snow Leopard, but not in Chrome in
// some conditions. As a result, Webkit typically recognizes the syntax but
// will sometimes throw a false positive, thus we must do a more thorough check:
if (ret && (!usePrefix || 'webkitPerspective' in docElement.style)) {
var mq;
var defaultStyle = '#modernizr{width:0;height:0}';
// Use CSS Conditional Rules if available
if (Modernizr.supports) {
mq = '@supports (perspective: 1px)';
} else {
// Otherwise, Webkit allows this media query to succeed only if the feature is enabled.
// `@media (transform-3d),(-webkit-transform-3d){ ... }`
mq = '@media (transform-3d)';
if (usePrefix) {
mq += ',(-webkit-transform-3d)';
}
}
mq += '{#modernizr{width:7px;height:18px;margin:0;padding:0;border:0}}';
testStyles(defaultStyle + mq, function(elem) {
ret = elem.offsetWidth === 7 && elem.offsetHeight === 18;
});
}
return ret;
});
});