Skip to content

Instantly share code, notes, and snippets.

@edankwan
Last active October 31, 2017 10:12
Show Gist options
  • Save edankwan/4389601 to your computer and use it in GitHub Desktop.
Save edankwan/4389601 to your computer and use it in GitHub Desktop.
preserve-3d test for Modernizr based on https://gist.github.com/4123325
(function(Modernizr, win){
Modernizr.addTest('csstransformspreserve3d', function () {
var prop = Modernizr.prefixed('transformStyle');
var val = 'preserve-3d';
var computedStyle;
if(!prop) return false;
prop = prop.replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }).replace(/^ms-/,'-ms-');
Modernizr.testStyles('#modernizr{' + prop + ':' + val + ';}', function (el, rule) {
computedStyle = win.getComputedStyle ? getComputedStyle(el, null).getPropertyValue(prop) : '';
});
return (computedStyle === val);
});
}(Modernizr, win));
@drus
Copy link

drus commented May 23, 2013

Great, you saved my time :)
Thanks for share it!

@mayloveless
Copy link

it won't work in Chrome 26 -,but i am not mean your code .

my problem here is:
when I use your code test Chrome 26- ,it shows it supported preserve-3d,so i wrote some css3 in the page.
However it couldn't do what preserve-3d shoud do,it won't keep 3d position. Chrome 29 did just fine.
plz help me with it. thx:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment