Detecting 'transform: translate3d' support

前端 未结 12 1652
遥遥无期
遥遥无期 2020-11-29 19:03

Does anyone know how I would detect transform: translate3d(x,y,z) support is available?

My issue is that I want to use translate3d across b

12条回答
  •  醉梦人生
    2020-11-29 19:40

    Was tinkering around with a way to check for 3d support.. used this implementation from Jeffery Way in this article. Allows for less code and more use cases ;)

    /**
    * Test For CSS3 property support
    * use 'perspective' to test for 3d support
    */
    var supports = (function() {
    
        'use strict';
    
        var div = document.createElement('div'),
            vendors = 'Khtml ms O Moz Webkit'.split(' '),
            len = vendors.length;
    
        return function(prop) {
    
            if (prop in div.style) return true;
    
            prop = prop.replace(/^[a-z]/, function(val) {
                return val.toUpperCase();
            });
    
            while(len--) {
                if (vendors[len] + prop in div.style) {
                    return true;
                } 
            }
    
            return false;
        };
    })();
    
    if(supports('perspective')) {
        // do 3d stuff
    }
    

提交回复
热议问题