1.效果图
海贼王木马
2.实现原理
2.1 首先利用transform中的rotateY和translateZ属性移动图片,使图片围成一圈;(最中间的图片不需要设置任何属性,可以作为其他图片的位置参考)
2.2 利用animation动画使全部图片开始旋转;
3.HTML代码
<body>
<section>
<div><img src="images/02-h1.png" alt=""></div>
<div><img src="images/02-h2.png" alt=""></div>
<div><img src="images/02-h3.png" alt=""></div>
<div><img src="images/02-h4.png" alt=""></div>
<div><img src="images/02-h5.png" alt=""></div>
<div><img src="images/02-h6.png" alt=""></div>
<div><img src="images/02-h7.png" alt=""></div>
</section>
</body>
4.CSS代码
/* 初始化 */
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
/* 定义动画 */
@keyframes rotate {
0% {
transform: rotateY(0);
}
100% {
transform: rotateY(360deg);
}
}
body {
/* 设置视点 */
perspective: 800px;
background-color: #01847f;
}
section {
position: relative;
width: 300px;
height: 200px;
margin: 200px auto;
transform: translateX(-50%);
/* 调用动画 */
/* 设为3d可视 */
transform-style: preserve-3d;
animation: rotate 15s linear infinite;
}
section div {
position: absolute;
top: 0;
right: 0;
width: 100%;
height: 100%;
}
section img {
width: 300px;
height: 200px;
}
section div:nth-child(1) {
transform: rotateY(0) translateZ(300px);
}
section div:nth-child(2) {
transform: rotateY(60deg) translateZ(300px);
}
section div:nth-child(3) {
transform: rotateY(120deg) translateZ(300px);
}
section div:nth-child(4) {
transform: rotateY(180deg) translateZ(300px);
}
section div:nth-child(5) {
transform: rotateY(240deg) translateZ(300px);
}
section div:nth-child(6) {
transform: rotateY(300deg) translateZ(300px);
}
5.动画介绍
1. 动画语法:
@keyframes 动画名称 {
0% { //百分比要是整数,就是总的时间的划分;
}
100% {
}
}
2.常用动画基本属性
属性 | 描述 |
---|---|
@keyframes | 规定动画 |
animation-name | 规定了@keyframes动画的名称(必须) |
animation-duration | 规定动画一个周期的时间,默认是0(必须) |
animation-timing-function | 规定动画的速度曲线,默认是ease |
animation-delay | 规定动画何时开始,默认是0 |
animation-iteration-count | 规定动画被播放的次数,默认是1,还有infinite |
animation-direction | 规定动画是否在下一周期逆向播放,默认是normal,alternate |
animation-play-state | 规定动画是否正在运行或暂停,默认是running,paused |
animation-fill-mode | 规定动画结束后状态,保持forwards回到起始backwards |
注:更多属性可到官网查询
3.简写:
animation: 动画名称 持续时间 运动曲线 何时开始 播放次数 是否反方向
动画起始或结束状态;(省略即默认值,前两个必写)