Gig*_*San 2 html css animation css-animations
HTML:
<div class="container">
<div class="coin">
<div class="face heads">
Hey!
</div>
<div class="face tails">
Ho!
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,谚语.coin由两个 s 组成,由两个具有不同 的.face重叠 s 表示。divz-index
.tails当达到关键帧的 50% 时,动画是否不应该渲染脸部,因为整个脸部.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);
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="coin">
<div class="face heads">
Hey!
</div>
<div class="face tails">
Ho!
</div>
</div>
</div>Run Code Online (Sandbox Code Playgroud)