css - ie8 : is there possible to have transform in pseudo element?

标签 css internet-explorer-8 css-transforms

我需要在 ie8 上进行 css 转换,可以吗?

我试过 progid:DXImageTransform 但它不适用于伪元素

.stack.twisted:before {
    -ms-transform:rotate(8deg); /* IE 9 */
    -webkit-transform: rotate(8deg);
    -moz-transform: rotate(8deg);
    transform: rotate(8deg);
    -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678, M12=-0.70710678, M21=0.70710678, M22=0.70710678,sizingMethod='auto expand')";filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678, M12=-0.70710678, M21=0.70710678, M22=0.70710678,sizingMethod='auto expand');

}   

为了清楚起见,我需要在 ie8 中使用 css3 中的变换之类的旋转效果。所以我找到了 progid:DXImageTransform.Microsoft.Matrix 但它在伪元素中不起作用。还有其他方法吗?

最佳答案

有很多解决方案和一些非常酷的库,但我需要用一小段独立的代码来处理同样的问题。这也解决了矩阵变换的 ie6、ie7 和 ie8 问题,使用 Top/Left 作为原点而不是像所有其他的那样使用中心:

//
// Rotate a <DIV> element
//
// - DIV position must be absolute or relative
// - Will use the center point of DIV as origin for tilt
//
// I think it will work on most browsers (including ie6, ie7 & ie8)
//
function divRotate( divObj, divTop, divLeft, divHeight, divWidth, newAngleDeg )
    {
    var radAngle = Math.PI * newAngleDeg / 180;
    var spinAngle = radAngle;

    if ( window.navigator.userAgent.indexOf ( 'MSIE ' ) <= 0 || typeof document.documentElement.style.opacity!='undefined' )
        radAngle = -radAngle;

    var sinAngle = parseFloat(parseFloat(Math.sin(radAngle)).toFixed(8));
    var cosAngle = parseFloat(parseFloat(Math.cos(radAngle)).toFixed(8));

    var m11 = cosAngle;
    var m12 = -sinAngle;
    var m21 = sinAngle;
    var m22 = cosAngle;

    if ( window.navigator.userAgent.indexOf ( 'MSIE ' ) <= 0 || typeof document.documentElement.style.opacity!='undefined' )
        {
        divObj.style.WebkitTransform = 'matrix('+ m11 +','+ m12 +','+ m21 +','+ m22 +',' + 0 + ',' + 0 + ')';
        divObj.style.MozTransform = 'matrix('+ m11 +','+ m12 +','+ m21 +','+ m22 +',' + 0 + 'px,' + 0 + 'px)';
        divObj.style.msTransform = 'matrix('+ m11 +','+ m12 +','+ m21 +','+ m22 +',' + 0 + ',' + 0 + ')';
        divObj.style.OTransform = 'matrix('+ m11 +','+ m12 +','+ m21 +','+ m22 +',' + 0 + ',' + 0 + ')';
        divObj.style.transform = 'matrix('+ m11 +','+ m12 +','+ m21 +','+ m22 +',' + 0 + ',' + 0 + ')';

        divObj.style.top = divTop + 'px';
        divObj.style.left = divLeft + 'px';

        return;
        }

    var sinSpinAngle = -parseFloat(parseFloat(Math.sin(-spinAngle)).toFixed(8));
    var cosSpinAngle = parseFloat(parseFloat(Math.cos(-spinAngle)).toFixed(8));
    var sinAnglePerp = parseFloat(parseFloat(Math.sin(radAngle-Math.PI)).toFixed(8));
    var cosAnglePerp = parseFloat(parseFloat(Math.cos(radAngle-Math.PI)).toFixed(8));
    var halfHeight = divHeight/2;
    var halfWidth = divWidth/2;
    var radius = Math.sqrt(halfHeight*halfHeight + halfWidth*halfWidth);

    var ulx = divLeft + halfWidth - radius*cosSpinAngle + sinAnglePerp*halfHeight;
    var uly = divTop + halfHeight - radius*sinSpinAngle + cosAnglePerp*halfHeight;

    var urx = radius*cosSpinAngle + divLeft + halfWidth + sinAnglePerp*halfHeight;
    var ury = radius*sinSpinAngle + divTop + halfHeight + cosAnglePerp*halfHeight;

    var lrx = radius*cosSpinAngle + divLeft + halfWidth - sinAnglePerp*halfHeight;
    var lry = radius*sinSpinAngle + divTop + halfHeight - cosAnglePerp*halfHeight;

    var llx = divLeft + halfWidth - radius*cosSpinAngle - sinAnglePerp*halfHeight;
    var lly = divTop + halfHeight - radius*sinSpinAngle - cosAnglePerp*halfHeight;

    divObj.style.filter = "filter: progid:DXImageTransform.Microsoft.Matrix( M11="+m11+", M12="+m12+", M21="+m21+", M22="+m22+", sizingMethod='auto expand' );";

    var spinTop = Math.min( uly, ury, lry, lly );
    var spinRight = Math.max( ulx, urx, lrx, llx );
    var spinBottom = Math.max( uly, ury, lry, lly );
    var spinLeft = Math.min( ulx, urx, lrx, llx );

    divObj.style.top = spinTop + 'px';
    divObj.style.right = spinRight + 'px';
    divObj.style.bottom = spinBottom + 'px';
    divObj.style.left = spinLeft + 'px';
    }

关于css - ie8 : is there possible to have transform in pseudo element?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11339929/

相关文章:

html - 不均匀的 CSS 变换动画

html - 转换节点上的 CSS 边框

html - 如何使用一个类的对齐方式和另一个类的字体?

jquery/IE mousemove 事件随着工具提示消失而触发,但鼠标没有移动

css - 同时使用 scaleX 和 translationX (VelocityJS)

css - IE 8 圆 Angular 问题

jquery IE8 - 一起使用 live ('blur' ,函数)和 live ('change' ,函数)

css - 如何通过内联 css 样式使用 Watir 查找元素

javascript - 加载更多//显示更少按钮高级

html - 输入类型文本的边界半径问题