用div+css写一段输出白雪公主跳舞的完整代码
以下是用div+css写的输出白雪公主跳舞的完整代码:
HTML代码:
<div class="wrapper">
<div class="dance-container">
<div class="dance-step step1"></div>
<div class="dance-step step2"></div>
<div class="dance-step step3"></div>
<div class="dance-step step4"></div>
<div class="dance-step step5"></div>
<div class="dance-step step6"></div>
<div class="dance-step step7"></div>
<div class="dance-step step8"></div>
</div>
</div>
CSS代码:
.wrapper {
width: 600px;
margin: 0 auto;
text-align: center;
}
.dance-container {
width: 300px;
height: 300px;
margin: 0 auto;
position: relative;
}
.dance-step {
position: absolute;
width: 100px;
height: 100px;
border-radius: 50%;
background: #f8c0c0;
animation-duration: 1s;
animation-timing-function: ease-in-out;
animation-fill-mode: forwards;
}
.step1 {
top: 0;
left: 50%;
transform: translateX(-50%);
animation-name: step1;
}
.step2 {
top: 50%;
left: 0;
transform: translateY(-50%);
animation-name: step2;
}
.step3 {
top: 50%;
left: 100%;
transform: translateY(-50%);
animation-name: step3;
}
.step4 {
top: 100%;
left: 50%;
transform: translateX(-50%);
animation-name: step4;
}
.step5 {
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation-name: step5;
}
.step6 {
top: 100%;
left: 0;
transform: translate(0, -100%);
animation-name: step6;
}
.step7 {
top: 100%;
left: 100%;
transform: translate(-100%, -100%);
animation-name: step7;
}
.step8 {
top: 100%;
left: 50%;
transform: translateX(-50%) translate(0, -100%);
animation-name: step8;
}
@keyframes step1 {
0% {
transform: translateX(-50%) translateY(-100%);
}
100% {
transform: translateX(-50%) translateY(0);
}
}
@keyframes step2 {
0% {
transform: translateX(-100%) translateY(-50%);
}
100% {
transform: translateX(0) translateY(-50%);
}
}
@keyframes step3 {
0% {
transform: translateX(100%) translateY(-50%);
}
100% {
transform: translateX(0) translateY(-50%);
}
}
@keyframes step4 {
0% {
transform: translateX(-50%) translateY(100%);
}
100% {
transform: translateX(-50%) translateY(0);
}
}
@keyframes step5 {
0% {
transform: translate(-50%, -100%);
}
100% {
transform: translate(-50%, 0);
}
}
@keyframes step6 {
0% {
transform: translate(0, -100%);
}
100% {
transform: translate(0, 0);
}
}
@keyframes step7 {
0% {
transform: translate(-100%, -100%);
}
100% {
transform: translate(0, 0);
}
}
@keyframes step8 {
0% {
transform: translateX(-50%) translate(0, -100%);
}
100% {
transform: translateX(-50%) translate(0, 0);
}
}
这段代码实现了一个八个步骤的跳舞动画,每个步骤都是一个圆形,用CSS的animation实现动画效果。通过设置不同的位置和动画名称,让圆形在屏幕上跳舞,最终呈现出白雪公主跳舞的效果。
原文地址: https://www.cveoy.top/t/topic/Nh1 著作权归作者所有。请勿转载和采集!