以编程方式设置Transform Origin的正确方法

时间:2014-08-21 22:38:53

标签: javascript transform

这是以编程方式设置转换源,跨浏览器的正确方法吗?感谢

var s = element.style;

s.webkitTransformOrigin = transform;
   s.MozTransformOrigin = transform;      //cap first letter
    s.msTransformOrigin = transform;
     s.OTransformOrigin = transform;      //cap first letter
      s.transformOrigin = transform;

1 个答案:

答案 0 :(得分:0)

所以我决定使用Modernizr这样做:

transform: null,
transformOrigin: null,

initCss: function() {
    this.transform = Modernizr.prefixed('transform');
    this.transformOrigin = Modernizr.prefixed('transformOrigin');
},

setTransform: function(element, transform) {
    if (this.transform) {
        element.style[this.transform] = transform;
    }
    else {                                //fallback just in case
        var s = element.style;

        s.webkitTransform = transform;
        s.MozTransform = transform;       //cap first letter
        s.msTransform = transform;
        s.OTransform = transform;         //cap first letter
        s.transform = transform;
    }
},

思想?