空间-平移
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/f9cf9c8cddcfa346833472debffc1b14.png)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>空间平移</title>
<style>
.box {
width: 200px;
height: 200px;
margin: 100px auto;
background-color: pink;
transition: all 0.5s;
}
.box:hover {
transform: translateX(100px);
transform: translateY(-100%);
transform: translateZ(300px);
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
视距
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/2c2a447222037cc624262f7cfb506514.png)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>透视效果</title>
<style>
.father {
perspective: 1000px;
}
.son {
width: 200px;
height: 200px;
margin: 100px auto;
background-color: pink;
transition: all 0.5s;
}
.son:hover{
transform: translateZ(300px);
}
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
</body>
</html>
空间旋转-Z轴
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/db0228ca0fa56108cca58042847fc809.png)
<!DOCTYPE html>
<html lang="en">
<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>空间旋转-Z轴</title>
<style>
.box {
width: 300px;
margin: 100px auto;
}
img {
width: 300px;
transition: all 2s;
}
.box img:hover {
transform: rotateZ(360deg);
}
</style>
</head>
<body>
<div class="box">
<img src="./images/hero.jpeg" alt="" />
</div>
</body>
</html>
空间旋转-X轴
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/f6983128fc5940ab81e2233f3f064288.png)
<!DOCTYPE html>
<html lang="en">
<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>空间旋转-X轴</title>
<style>
.box {
width: 300px;
margin: 100px auto;
}
img {
width: 300px;
transition: all 2s;
}
.box {
perspective: 1000px;
}
.box img:hover {
transform: rotateX(60deg);
transform: rotateX(-60deg);
}
</style>
</head>
<body>
<div class="box">
<img src="./images/hero.jpeg" alt="" />
</div>
</body>
</html>
空间旋转-Y轴
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/8de0c7c013f38e8e4989de96eaa46b1f.png)
<!DOCTYPE html>
<html lang="en">
<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>空间旋转-Y轴</title>
<style>
.box {
width: 300px;
margin: 100px auto;
}
img {
width: 300px;
transition: all 2s;
}
.box {
perspective: 1000px;
}
.box img:hover {
transform: rotateY(60deg);
transform: rotateY(-60deg);
}
</style>
</head>
<body>
<div class="box">
<img src="./images/hero.jpeg" alt="" />
</div>
</body>
</html>
立体呈现
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/724464395b4a1591cbef2798b373a5fa.png)
<!DOCTYPE html>
<html lang="en">
<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>立体呈现</title>
<style>
.cube {
position: relative;
width: 200px;
height: 200px;
margin: 100px auto;
transition: all 2s;
transform-style: preserve-3d;
}
.cube div {
position: absolute;
left: 0;
top: 0;
width: 200px;
height: 200px;
}
.front {
background-color: orange;
transform: translateZ(100px);
}
.back {
background-color: green;
transform: translateZ(-100px);
}
.cube:hover {
transform: rotateY(90deg);
}
</style>
</head>
<body>
<div class="cube">
<div class="front">前面</div>
<div class="back">后面</div>
</div>
</body>
</html>
3D导航
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c4dd0ec8dc1f7baeed7baea540f94bf2.png)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>3D导航</title>
<style>
ul {
margin: 0;
padding: 0;
list-style: none;
}
.nav {
width: 300px;
height: 40px;
margin: 50px auto;
}
.nav ul {
display: flex;
}
.nav li {
position: relative;
width: 100px;
height: 40px;
line-height: 40px;
transition: all 0.5s;
transform-style: preserve-3d;
}
.nav li a {
position: absolute;
left: 0;
top: 0;
display: block;
width: 100%;
height: 100%;
text-align: center;
text-decoration: none;
color: #fff;
}
.nav li a:first-child {
background-color: green;
transform: translateZ(20px);
}
.nav li a:last-child {
background-color: orange;
transform: rotateX(90deg) translateZ(20px);
}
.nav li:hover {
transform: rotateX(-90deg);
}
</style>
</head>
<body>
<div class="nav">
<ul>
<li>
<a href="#">首页</a>
<a href="#">Index</a>
</li>
<li>
<a href="#">登录</a>
<a href="#">Login</a>
</li>
<li>
<a href="#">注册</a>
<a href="#">Register</a>
</li>
</ul>
</div>
</body>
</html>
空间-缩放
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/27e03a7484bc881aed920276bc4018a8.png)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>空间缩放</title>
<style>
ul {
margin: 0;
padding: 0;
list-style: none;
}
.nav {
width: 300px;
height: 40px;
margin: 50px auto;
}
.nav li {
position: relative;
float: left;
width: 100px;
height: 40px;
line-height: 40px;
transition: all 0.5s;
transform-style: preserve-3d;
transform: scale3d(0.5, 2, 3);
}
.nav li a {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
text-align: center;
text-decoration: none;
color: #fff;
}
.nav li a:first-child {
background-color: green;
transform: translateZ(20px);
}
.nav li a:last-child {
background-color: orange;
transform: rotateX(90deg) translateZ(20px);
}
.nav li:hover {
transform: rotateX(-90deg);
}
</style>
</head>
<body>
<div class="nav">
<ul>
<li>
<a href="#">首页</a>
<a href="#">Index</a>
</li>
<li>
<a href="#">登录</a>
<a href="#">Login</a>
</li>
<li>
<a href="#">注册</a>
<a href="#">Register</a>
</li>
</ul>
</div>
</body>
</html>
动画-体验
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ae607b73828b018ce19354513430bf78.png)
<!DOCTYPE html>
<html lang="en">
<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>体验动画</title>
<style>
div {
width: 100px;
height: 100px;
background-color: pink;
animation: change 1s infinite alternate;
}
@keyframes change {
0% {
transform: translate(0);
}
100% {
transform: translate(600px);
}
}
</style>
</head>
<body>
<div></div>
</body>
</html>
动画实现步骤
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/8a9ffec23efd95be6f27cd4f8fca2f56.png)
<!DOCTYPE html>
<html lang="en">
<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>动画实现步骤</title>
<style>
.box {
width: 200px;
height: 100px;
background-color: pink;
animation: change 1s;
}
@keyframes change {
from {
width: 200px;
}
to {
width: 800px;
}
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
animation复合属性
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/b39c609c881d881785fed26b97c44f19.png)
<!DOCTYPE html>
<html lang="en">
<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>animation复合属性</title>
<style>
.box {
width: 200px;
height: 100px;
background-color: pink;
animation: change 1s forwards;
}
@keyframes change {
from {
width: 200px;
}
to {
width: 800px;
}
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
animation拆分写法
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0210cafa7d9d1be0510d61a0fad96f83.png)
<!DOCTYPE html>
<html lang="en">
<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>animation拆分写法</title>
<style>
.box {
width: 200px;
height: 100px;
background-color: pink;
animation-name: change;
animation-duration: 1s;
animation-iteration-count: infinite;
}
.box:hover {
animation-play-state: paused;
}
@keyframes change {
0% {
width: 200px;
}
100% {
width: 800px;
}
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
走马灯
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/913d23a8c9cd9729fc396c393577d781.png)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>走马灯</title>
<style>
* {
padding: 0;
margin: 0;
}
li {
list-style: none;
}
img {
display: block;
width: 200px;
}
.box {
width: 600px;
height: 112px;
border: 5px solid #000;
margin: 100px auto;
overflow: hidden;
}
.box ul {
display: flex;
animation: move 6s infinite linear;
}
@keyframes move {
0% {
transform: translate(0);
}
100% {
transform: translate(-1400px);
}
}
.box:hover ul {
animation-play-state: paused;
}
</style>
</head>
<body>
<div class="box">
<ul>
<li><img src="./images/1.jpg" alt="" /></li>
<li><img src="./images/2.jpg" alt="" /></li>
<li><img src="./images/3.jpg" alt="" /></li>
<li><img src="./images/4.jpg" alt="" /></li>
<li><img src="./images/5.jpg" alt="" /></li>
<li><img src="./images/6.jpg" alt="" /></li>
<li><img src="./images/7.jpg" alt="" /></li>
<li><img src="./images/1.jpg" alt="" /></li>
<li><img src="./images/2.jpg" alt="" /></li>
<li><img src="./images/3.jpg" alt="" /></li>
</ul>
</div>
</body>
</html>
精灵动画
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/52a24d893b2fb1f2ed1d2c4b5f204faf.png)
<!DOCTYPE html>
<html lang="en">
<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>精灵动画</title>
<style>
div {
width: 140px;
height: 140px;
border: 1px solid #000;
background-image: url(./images/bg.png);
animation: run 1s steps(12) infinite;
}
@keyframes run {
from {
background-position: 0 0;
}
to {
background-position: -1680px 0;
}
}
</style>
</head>
<body>
<div></div>
</body>
</html>
多组动画
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/52e5c50c2d39a2673489ae8fda45a16a.png)
<!DOCTYPE html>
<html lang="en">
<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>多组动画</title>
<style>
div {
width: 140px;
height: 140px;
background-image: url(./images/bg.png);
animation:
run 1s steps(12) infinite,
move 3s forwards
;
}
@keyframes run {
to {
background-position: -1680px 0;
}
}
@keyframes move {
100% {
transform: translate(800px);
}
}
</style>
</head>
<body>
<div></div>
</body>
</html>
全民出游季
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/5407bbbdfe64affc4b8f7bd55836be8b.png)
html
<!DOCTYPE html>
<html lang="en">
<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>全民出游季</title>
<link rel="stylesheet" href="./css/index.css">
</head>
<body>
<div class="cloud">
<img src="./images/yun1.png" alt="">
<img src="./images/yun2.png" alt="">
<img src="./images/yun3.png" alt="">
</div>
<div class="text">
<img src="./images/font1.png" alt="">
</div>
</body>
</html>
css
* {
margin: 0;
padding: 0;
}
/* 大背景 */
/* 默认状态HTML和body的高度是0,所以导致cover缩放背景图不成功 */
html {
height: 100%;
}
body {
height: 100%;
background: url(../images/f1_1.jpg) no-repeat center 0 / cover;
/* background-size: cover; */
}
/* 云 */
.cloud img {
position: absolute;
left: 50%;
}
.cloud img:nth-child(1) {
margin-left: -250px;
top: 20px;
animation: cloud 1s infinite alternate linear;
}
.cloud img:nth-child(2) {
margin-left: 400px;
top: 100px;
animation: cloud 1s infinite alternate linear 0.4s;
}
.cloud img:nth-child(3) {
margin-left: -550px;
top: 200px;
animation: cloud 1s infinite alternate linear 0.6s;
}
@keyframes cloud {
100% {
transform: translate(20px);
}
}
/* 文字 */
.text img {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
animation: text 1s;
}
/* 默认 → 小 → 大 → 小 → 默认 */
@keyframes text {
0% {
transform: translate(-50%, -50%) scale(1);
}
20% {
transform: translate(-50%, -50%) scale(0.1);
}
40% {
transform: translate(-50%, -50%) scale(1.4);
}
70% {
transform: translate(-50%, -50%) scale(0.8);
}
100% {
transform: translate(-50%, -50%) scale(1);
}
}