预先计算变换原点偏移量

时间:2012-10-04 09:06:24

标签: javascript jquery css3 rotation css-transforms

当我在旋转后更改css3中的transform-origin属性时,元素会跳回到原始位置的中心。 有没有办法计算这个距离?我想在不同的起源进行平稳的旋转。

我写了一个公式。它运作良好,但前提是我知道未来轮换的起源。

var newx = p2x - Math.sqrt(Math.pow(p2x - p1x, 2) + Math.pow(p2y - p1y, 2)) * Math.sin( -((degree * (Math.PI/180))) + Math.atan( ((p2x - p1x)/(p2y - p1y)) ));
var newy = p2y - Math.sqrt(Math.pow(p2x - p1x, 2) + Math.pow(p2y - p1y, 2)) * Math.cos( -((degree * (Math.PI/180))) + Math.atan( ((p2x - p1x)/(p2y - p1y)) ));

p1x和p1y是未来的值,p2x和p2y是当前轮换的原点。

0 个答案:

没有答案