使用 webkit 3d 变换控制旋转轴

发布于 2024-11-18 08:13:08 字数 1030 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吻风 2024-11-25 08:13:08

在你的包装器上尝试这个,

-webkit-transform-origin: 50% 0 0;

尽管你可能或可能不需要显式设置它的宽度。

Try this on your wrapper

-webkit-transform-origin: 50% 0 0;

Though you may or may not have to have its width explicitly set.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文