前言
利用3d动画写了一个旋转木马
提示:以下是本篇文章正文内容,下面案例可供参考
一、旋转木马展示
二、旋转木马源代码
代码如下(示例):
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
perspective: 1000px;
}
section {
position: relative;
transform-style: preserve-3d;
width: 300px;
height: 168px;
margin: 150px auto;
animation: move 10s linear infinite;
background: url(../media/0.jpg) no-repeat;
}
section div {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
/* background: url(../media/dog.jpg) no-repeat; */
}
section:hover {
animation-play-state: paused;
}
section div:nth-child(1) {
background: url(../media/1.jpg) no-repeat;
transform: translateZ(300px);
transform: rotateY(0deg) translatez(300px);
}
section div:nth-child(2) {
/* 先旋转好了移动 */
background: url(../media/2.jpg) no-repeat;
transform: rotateY(60deg) translatez(300px);
}
section div:nth-child(3) {
/* 先旋转好了移动 */
background: url(../media/3.jpg) no-repeat;
transform: rotateY(120deg) translatez(300px);
}
section div:nth-child(4) {
/* 先旋转好了移动 */
background: url(../media/4.jpg) no-repeat;
transform: rotateY(180deg) translatez(300px);
}
section div:nth-child(5) {
/* 先旋转好了移动 */
background: url(../media/5.jpg) no-repeat;
transform: rotateY(240deg) translatez(300px);
}
section div:nth-child(6) {
/* 先旋转好了移动 */
background: url(../media/6.jpg) no-repeat;
transform: rotateY(300deg) translatez(300px);
}
@keyframes move {
0% {
transform: rotateY(0deg);
}
100% {
transform: rotateY(360deg);
}
}
</style>
</head>
<body>
<audio src="../media/蓝心羽 - 别怕,有光.flac" autoplay="autoplay" loop="loop" controls="controls"></audio>
<section>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
</body>
</html>