使用 webkit 3d 变换控制旋转轴
我正在使用 webkit 转换创建卡片翻转效果。我让它在一个部分中按照我喜欢的方式工作,其中我有一个围绕其中心轴旋转的 DIV,呈现出一张正在翻转的卡片的外观。
我现在想将相同的效果添加到页面转换中。我使用相同的 CSS 和 HTML 结构,但在这种情况下,我没有获得围绕中心轴旋转的效果。
相反,看起来变换是沿着锚定在对象左侧而不是中心的 y 轴旋转(因此它看起来像门打开,而不是卡片翻转)。
我一直在阅读规范,但无法弄清楚哪个属性控制旋转轴的位置。我需要添加或更改什么才能使翻转正常工作?
html 结构:
<div id="frontbackwrapper">
<div id="front"></div>
<div id="back"></div>
</div>
和 css(通过 jQuery 添加 .flip 来启动效果)
#frontbackwrapper {
position: absolute;
-webkit-perspective: 1000;
-webkit-transition-duration: 1s;
-webkit-transform-style: preserve-3d;
-webkit-transition: 1s;
}
#frontbackwrapper.flip {
-webkit-transform: rotateY(180deg);
}
#frontbackwrapper.flip #front,
#frontbackwrapper.flip #back {
-webkit-transform: rotateY(180deg);
-webkit-transition: 1s;
}
#front, #back {
position: absolute;
-webkit-backface-visibility: hidden;
}
#back {
-webkit-transform: rotateY(180deg);
}
I'm creating a card-flip effect using webkit transformations. I have it working as I like in one section, where I have a DIV that rotates around its center axis giving the look of a card that is flipping over.
I now want to add this same effect to a page transition. I'm using the same CSS and HTML structure, but in this case I'm not getting an effect that rotates around a center axis.
Instead, it looks like the transformation is rotating along the y axis anchored to the left of the object rather than the center (so it looks like a door opening, rather than a card flipping).
I've been reading through the spec's but can't figure out which property controls the rotation axis' position. What do I need to add or change with this to get the flip working?
html structure:
<div id="frontbackwrapper">
<div id="front"></div>
<div id="back"></div>
</div>
and the css (.flip is being added via jQuery to start the effect)
#frontbackwrapper {
position: absolute;
-webkit-perspective: 1000;
-webkit-transition-duration: 1s;
-webkit-transform-style: preserve-3d;
-webkit-transition: 1s;
}
#frontbackwrapper.flip {
-webkit-transform: rotateY(180deg);
}
#frontbackwrapper.flip #front,
#frontbackwrapper.flip #back {
-webkit-transform: rotateY(180deg);
-webkit-transition: 1s;
}
#front, #back {
position: absolute;
-webkit-backface-visibility: hidden;
}
#back {
-webkit-transform: rotateY(180deg);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你的包装器上尝试这个,
尽管你可能或可能不需要显式设置它的宽度。
Try this on your wrapper
Though you may or may not have to have its width explicitly set.