3D移动:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
@keyframes move {
0% {
transform: translate(0, 0);
}
100% {
transform: translate(1000px, 0)
}
}
div {
width: 100px;
height: 100px;
background-color: pink;
/* 动画名称 */
/* animation-name: move;
/* 持续时间 */
/* animation-duration: 2s;
/* 规定动画的曲线。默认ease */
/* animation-timing-function: ease; */
/* 规定何时开始 */
/* animation-delay: 2s; */
/* 播放次数默认是1 */
/* animation-iteration-count: infinite; */
/* 是否反方向播放 */
/* animation-direction: alternate; */
/* 动画简写:动画名称、持续时间、运动曲线、何时开始、播放次数、是否反方向、动画起始或结束状态 */
/* animation: name duration timing-function delay iteration-count direction fill-mode; */
animation: move 2s linear 0s 3 alternate forwards;
}
</style>
</head>
<body>
<div>
</div>
</body>
</html>
3D旋转:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
perspective: 250px;
}
img {
display: block;
margin: 100px auto;
transition: all 2s;
}
/* x轴旋转 */
/* img:hover {
transform: rotateX(360deg);
} */
/* y轴旋转 */
/* img:hover {
transform: rotateY(180deg);
} */
/* z轴旋转 */
img:hover {
/* transform: rotateZ(180deg); */
/* transform: rotate3d(x, y, z, deg); */
transform: rotate3d(1, 0, 0, 45deg);
}
</style>
</head>
<body>
<img src="dog.jpg" alt="">
</body>
</html>
3D呈现:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.body {
perspective: 500px;
}
.box {
position: relative;
width: 200px;
height: 200px;
margin: 100px auto;
transform: all 2s;
/* 让子元素保持3D立体空间 */
**transform-style: preserve-3d;**
}
.box:hover {
transform: rotateY(60deg);
}
.box div {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: pink;
}
.box div:last-child {
background-color: green;
transform: rotateX(45deg);
}
</style>
</head>
<body>
<div class="box">
<div></div>
<div></div>
</div>
</body>
</html>
</html>
两面翻转的盒子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
perspective: 500px;
}
.box {
position: relative;
width: 200px;
height: 200px;
margin: 100px auto;
transition: all .9s;
transform-style: preserve-3d;
}
.box:hover {
transform: rotateY(180deg);
}
.front,
.back {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 50%;
font-size: 30px;
color: #fff;
text-align: center;
line-height: 200px;
}
.front {
background-color: pink;
}
.back {
background-color: purple;
transform: rotateY(180deg);
}
</style>
</head>
<body>
<div class="box">
<div class="front">黑马程序员</div>
<div class="back">我等你</div>
</div>
</body>
</html>