简体   繁体   English

在IE8中转换对象(仅旋转),类似于使用CSS3 transform(rotate),transform-origin

[英]transforming an object (rotation only) in IE8, similar to using CSS3 transform(rotate), transform-origin

I am trying to get an application working in IE8, and I have been hung up on trying to get my CSS transforms working properly in IE. 我试图让一个应用程序在IE8中工作,而我一直在试图使我的CSS转换在IE8中正常工作。

I am able to calculate my angle using this code: 我可以使用以下代码计算角度:

//LEGACY IE ROTATE
var deg2radians = Math.PI * 2 / 360,
    rad = s.stone_rotation * deg2radians,
    costheta = Math.cos(rad),
    sintheta = Math.sin(rad),
    matrixValues = 'M11=' + costheta + ', M12='+ (-sintheta) +', M21='+ sintheta +', M22='+ costheta;

I then set the MS filter in an inline style using an inline styles: 然后,我使用内联样式将MS过滤器设置为内联样式:

element.style.cssText =  "filter:progid:DXImageTransform.Microsoft.Matrix(" + matrixValues + ")";

However, IE doesn't keep the origin point, so the rotation works, but the location of the item is not proper. 但是,IE不会保留原点,因此可以旋转,但是项目的位置不合适。 I've been looking into some plugins/libraries... such as sylvester, and a few other jQuery plugins. 我一直在研究一些插件/库...,例如sylvester和其他一些jQuery插件。 But i'd rather just get this working on my own, as I am building this all without any library. 但是我宁愿让它自己工作,因为我没有任何库就能构建所有这些。

I just need some help with the math to get the origin point set properly. 我只需要数学上的一些帮助即可正确设置原点。 I have variables (top, left, imgW, imgH) for the top/left/width/height for each object. 我有每个对象的顶部/左侧/宽度/高度的变量(顶部,左侧,imgW,imgH)。

Of course, everything with the CSS3 side of things works fine, just using the transform-origin along with rotate, and the matrix wasn't super difficult, but i can't figure out how to do the reference point. 当然,CSS3方面的所有东西都可以正常工作,仅将transform-origin与旋转一起使用,并且矩阵并不是超级困难,但是我不知道如何做参考点。

thanks! 谢谢!

If you are trying to set origin at center of element, you can use something like this: 如果您尝试将原点设置为元素的中心,则可以使用以下方法:

rotate = function (degrees) {

    while (degrees > 360) {
        degrees -= 360;

    }

    while (degrees < 0) {
        degrees += 360;

    }

    var matrix = element.filters.item("DXImageTransform.Microsoft.Matrix"),
        degrees = degrees,
        rad = (degrees * Math.PI) / 180,
        costheta = Math.cos(rad),
        sintheta = Math.sin(rad);

    matrix.M11 =  costheta;
    matrix.M12 = -sintheta;
    matrix.M21 =  sintheta;
    matrix.M22 =  costheta;

    rad %= Math.PI;
    if (rad > Math.PI / 2) rad = Math.PI - rad;

    costheta = Math.cos(rad),
    sintheta = Math.sin(-rad);

    element.style.top = y + Math.floor((h - h * costheta + w * sintheta) / 2) + 'px';
    element.style.left = x + Math.floor((w - w * costheta + h * sintheta) / 2) + 'px';

}

It's from my own library and it's not perfect, but good enough for me at least. 它来自我自己的库,虽然不完美,但至少对我来说足够好。

You can use the javascript library to fix IE8 and lower 您可以使用javascript库修复IE8及更低版本

http://www.useragentman.com/blog/2010/03/09/cross-browser-css-transforms-even-in-ie/ http://www.useragentman.com/blog/2010/03/09/cross-browser-css-transforms-even-in-ie/

and continue using CSS 并继续使用CSS

#o1 {
    position: absolute;
    top: 25px;
    left: 25px;
    border: solid 1px black;
    position: absolute;
    width: 100px;
    height: 100px;
    padding: 10px;
    background-color: white;
    -sand-transform: rotate(45deg);
}

using only the keyword -sand-transform 仅使用关键字-sand-transform

You can see an example in 您可以在中看到一个示例

http://www.useragentman.com/tests/cssSandpaper/rotateTest.html http://www.useragentman.com/tests/cssSandpaper/rotateTest.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM