用HTML与CSS写海贼王旋转木马图

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: 动画名称 持续时间 运动曲线 何时开始 播放次数 是否反方向
动画起始或结束状态;(省略即默认值,前两个必写)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值