我最近在 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;');