gpt4 book ai didi

css - HTML5 旋转动画 - 如何显示 "the other side of the coin"?

转载 作者:行者123 更新时间:2023-12-02 21:06:53 25 4
gpt4 key购买 nike

考虑this JSFiddle rotation example

HTML:

<div class="container">
<div class="coin">
<div class="face heads">
Hey!
</div>
<div class="face tails">
Ho!
</div>
</div>
</div>

CSS:

@keyframes rotation {
0% {
transform: rotate3d(0, 1, 0, 0deg);
}
50% {
transform: rotate3d(0, 1, 0, 180deg);
}
100% {
transform: rotate3d(0, 1, 0, 360deg);
}
}

.container {
background-color: blue;
width: 100px;
height: 100px;
}

.coin {
position: relative;
top: 25px;
left: 25px;
width: 50px;
height: 50px;
text-align: center;
line-height: 50px;
animation-name: rotation;
animation-iteration-count: infinite;
animation-timing-function: linear;
animation-duration: 2.5s;
}

.face {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 50%;
}

.heads {
background-color: green;
z-index: 2;
}

.tails {
background-color: gray;
z-index: 1;
}

如您所见,众所周知的 .coin 由两个 .face 组成,由两个具有不同 的重叠 div 表示>z-index.

当到达关键帧的 50% 时,动画不应该渲染 .tails 面吗,因为整个 .coin 正在围绕 Y 轴旋转?还是我对 HTML5 的期望太高了?或者我只是做错了什么?

预先感谢您的任何澄清!

最佳答案

我必须做一些研究,并在 David Walsh- CSS Flip 的帮助下

@keyframes rotation {
0% {
transform: rotate3d(0, 1, 0, 0deg);
}
50% {
transform: rotate3d(0, 1, 0, 180deg);
}
100% {
transform: rotate3d(0, 1, 0, 360deg);
}
}
.container {
background-color: blue;
width: 100px;
height: 100px;
perspective: 1000;
margin: 1em auto;
}
.coin {
position: relative;
top: 25px;
left: 25px;
width: 50px;
height: 50px;
text-align: center;
line-height: 50px;
animation-name: rotation;
animation-iteration-count: infinite;
animation-timing-function: linear;
animation-duration: 2.5s;
transform: rotateY(0deg);
transform-style: preserve-3d;
}
.face {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 50%;
backface-visibility: hidden;
}
.heads {
background-color: green;
z-index: 2;
transform: rotateY(0deg);
}
.tails {
background-color: gray;
z-index: 1;
transform: rotateY(180deg);
}
<div class="container">
<div class="coin">
<div class="face heads">
Hey!
</div>
<div class="face tails">
Ho!
</div>
</div>
</div>

关于css - HTML5 旋转动画 - 如何显示 "the other side of the coin"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35607055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com