CSS3 转换:多重起源?
是否可以在CSS3中指定左上角(0%,0%)的原点进行缩放,并指定不同的原点(中心)进行旋转?我只使用 webkit,如果有帮助的话。
我目前正在使用变换列表(即 -webkit-transform:scale(newScale)rotate(newRotate)
但似乎不可能在两次传递之间更改原点。是否有更好的方法来看待这个问题?目前,如果我缩放一个对象并以默认中心为原点旋转它,则该元素的位置现在已关闭,因此当您拖动该元素时,光标仍位于该元素的左上角,而它应该是将原点更改为中心。缩放它可以解决这个问题,但会带来旋转和翻转的新问题。
Is it possible to specify an origin at the top left (0%, 0%) for scaling, and a different origin (center) for rotation in CSS3? I am only working with webkit, if that helps.
I am currently using a transform list (i.e. -webkit-transform: scale(newScale) rotate(newRotate)
but it seems like it isn't possible to change the origin in-between passes. Is there a better way to look at this? Presently, if I scale an object and rotate it with an origin at the default center, the position of the element is now off and so when you drag the element, the cursor is still at the top left of the element, whereas it should be at the center. Changing the origin to the center to scale it fixes this, but presents new problems with rotation and flipping.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
找到了问题的一个很好的解决方案...通过创建父/子关系,如下所示:
我现在可以设置两个类,如下所示:
这将完全按照我想要的方式进行:以左上角的原点进行缩放,然后以原点在中心。瞧!
Found a good solution to the problem... by creating a parent/child relationship as follows:
I can now setup two classes as follows:
This will do exactly what I want: scale with an origin at the top left, then rotate with the origin at the center. Voila!
相反,请将原点 (0,0) 的缩放视为以原点中心进行缩放+平移。单独来看: 与以下
相同:
理论上,旋转原点中心应使角突出
sqrt(1/2)-0.5
,要求我们将原点向下和向右移动>20.71%
,但由于某种原因,webkit 变换算法为我们向下移动了一些东西(但还不够),并为我们缩放了原点(同样不完全)。因此,我们需要向右移动50%
并针对这种奇怪的行为进行一些调整:注意:我最初的答案是使用
div
和width:100px;< /code> 和
height100px;
需要translate3d(54px, 0, 0)
。Instead think of the scaling with origin (0,0) as a scaling+translation with origin center. In isolation the following:
is the same as:
In theory the rotation origin center should leave the corners sticking out by
sqrt(1/2)-0.5
requiring us to move the origin down and right by20.71%
, but for some reason the webkit transform algorithm moves things down for us (but not quite enough) and scales the origin for us (again not quite). Thus we need to move right by50%
and make some adjustments for this odd behavior:Note: my original answer was using a
div
withwidth:100px;
andheight100px;
which requires atranslate3d(54px, 0, 0)
.那怎么样:http://jsfiddle.net/22Byh/1/
What about that: http://jsfiddle.net/22Byh/1/