我最近需要此为IE7和8,以及决定写一小片JavaScript来处理计算IE特定矩阵值和偏移的滋扰。
为脚本来自这些链接的想法和解释:
http://www.boogdesign.com/examples/transforms/matrix-calculator.html
http://extremelysatisfactorytotalitarianism.com/blog/?p=1002
而这里的脚本(我使用节点运行它,但你也可以过去它在浏览器控制台):
// --- initialization
var w = 712; // object width
var h = 744; // object height
var deg = 48; // object rotation in degrees
// --- utils
function deg2rad(deg) {
return deg * (2 * Math.PI)/360;
}
var rad = deg2rad(deg);
// --- from http://www.boogdesign.com/examples/transforms/matrix-calculator.html
var costheta = Math.cos(rad);
var sintheta = Math.sin(rad);
var a = parseFloat(costheta).toFixed(8);
var c = parseFloat(-sintheta).toFixed(8);
var b = parseFloat(sintheta).toFixed(8);
var d = parseFloat(costheta).toFixed(8);
console.log('-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=' + a + ', M12=' + c + ', M21=' + b + ', M22=' + d + ', sizingMethod=\'auto expand\')";');
console.log('filter: progid:DXImageTransform.Microsoft.Matrix(M11=' + a + ', M12=' + c + ', M21=' + b + ', M22=' + d + ', sizingMethod=\'auto expand\');');
// --- from http://extremelysatisfactorytotalitarianism.com/blog/?p=1002
// calculate bounding box width and height
var bb_w = Math.abs(h * Math.sin(rad)) + Math.abs(w * Math.cos(rad));
var bb_h = Math.abs(h * Math.cos(rad)) + Math.abs(w * Math.sin(rad));
// calculate offsets
var offset_left = Math.floor((w/2) - (bb_w/2));
var offset_top = Math.floor((h/2) - (bb_h/2));
console.log('left: ' + offset_left + 'px;');
console.log('top: ' + offset_top + 'px;');
http://www.useragentman.com/blog/2010/03/09/cross-browser-css-transforms-even-in-ie/ – dockeryZ