火柴人是火柴组成的人类,用html做一个火柴人跳舞的动画
时间: 2024-05-11 22:19:00 浏览: 127
好的,我可以给您提供一个简单的 HTML 代码,用以制作一个火柴人跳舞的动画。请看下面的代码:
```
<!DOCTYPE html>
<html>
<head>
<title>火柴人跳舞动画</title>
<style>
#dance {
position: relative;
width: 100px;
height: 200px;
background-color: #fff;
border: 1px solid #000;
margin: 0 auto;
animation: dance 1s infinite;
}
#head {
position: absolute;
top: 0;
left: 50%;
width: 20px;
height: 20px;
background-color: #000;
border-radius: 50%;
transform: translateX(-50%);
}
#body {
position: absolute;
top: 20px;
left: 50%;
width: 10px;
height: 60px;
background-color: #000;
transform: translateX(-50%);
}
#left-arm {
position: absolute;
top: 30px;
left: 50%;
width: 30px;
height: 10px;
background-color: #000;
transform: translateX(-60%) rotate(-45deg);
transform-origin: top left;
animation: left-arm 1s infinite alternate;
}
#right-arm {
position: absolute;
top: 30px;
left: 50%;
width: 30px;
height: 10px;
background-color: #000;
transform: translateX(60%) rotate(45deg);
transform-origin: top right;
animation: right-arm 1s infinite alternate;
}
#left-leg {
position: absolute;
top: 80px;
left: 50%;
width: 20px;
height: 10px;
background-color: #000;
transform: translateX(-50%) rotate(-45deg);
transform-origin: top left;
animation: left-leg 1s infinite alternate;
}
#right-leg {
position: absolute;
top: 80px;
left: 50%;
width: 20px;
height: 10px;
background-color: #000;
transform: translateX(50%) rotate(45deg);
transform-origin: top right;
animation: right-leg 1s infinite alternate;
}
@keyframes dance {
0% {
transform: rotate(0deg);
}
50% {
transform: rotate(-10deg);
}
100% {
transform: rotate(0deg);
}
}
@keyframes left-arm {
0% {
transform: rotate(-45deg);
}
50% {
transform: rotate(-35deg);
}
100% {
transform: rotate(-45deg);
}
}
@keyframes right-arm {
0% {
transform: rotate(45deg);
}
50% {
transform: rotate(35deg);
}
100% {
transform: rotate(45deg);
}
}
@keyframes left-leg {
0% {
transform: rotate(-45deg);
}
50% {
transform: rotate(-35deg);
}
100% {
transform: rotate(-45deg);
}
}
@keyframes right-leg {
0% {
transform: rotate(45deg);
}
50% {
transform: rotate(35deg);
}
100% {
transform: rotate(45deg);
}
}
</style>
</head>
<body>
<div id="dance">
<div id="head"></div>
<div id="body"></div>
<div id="left-arm"></div>
<div id="right-arm"></div>
<div id="left-leg"></div>
<div id="right-leg"></div>
</div>
</body>
</html>
```
您可以在网页中打开这段代码,就可以看到火柴人跳舞的动画效果了。
阅读全文